I am a beginner, so what's my error here? What am I missing? Thanks. All the TextBoxes have value set in XAML.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void txt2_TextChanged(object sender, TextChangedEventArgs e)
{
int num1, num2, num3;
num1 = int.Parse(txt1.Text);
num2 = int.Parse(txt2.Text);
num3 = num1 * num2;
txt3.Text = num3.ToString();
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Debojyoti DasPosted May 1, 2013, 8:01 AM
Well, num3 can't be null because it's a value type, that means that txt3 is null. txtOut is null because the TextChanged event is raised when txtTwo's Text property is set in XAML which likely happens before the txtOut TextBox is created.
So the solution is to remove the TextChanged event from XAML and put it in the constructor, after InitializeComponent:
Pankaj PandeyPosted May 1, 2013, 7:46 AM
and when you are converting it to string it show null value exception.
you can control this acception by checking null value
if(
{
else
{
try it,if any issue,then tell me..i'll suggest you another way to fix it.