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();
}
}


Pankaj PandeyRank #642 · 3.7K reputationPosted May 1, 2013, 3:46 AM EDT
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.
Debojyoti Das4 reputationPosted May 1, 2013, 4:01 AM EDT
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:
public MainWindow() { InitializeComponent(); txtTwo.TextChanged += txtTwo_TextChanged; }