1

So I have a combobox:

<ComboBox IsEditable="True" TextBoxBase.TextChanged="textBox_Changed"/>

When the text in the combobox changes, it fires off the textBox_changed function:

private void textBox_Changed(object sender, RoutedEventArgs e)
{
    LinearGradientBrush gradient = new LinearGradientBrush(Colors.MistyRose, Colors.SandyBrown, new Point(0, 0), new Point(0, 1));
    this.saveButton.Background = gradient;
}

What this function does is change the background color of a button elsewhere on the window. So far this works perfectly. The issue appears when I try to use this same function with a TextBox instead of a Combobox:

<TextBox TextChanged="textBox_Changed"/>

When I run the application, I get the following error:

Object reference not set to an instance of an object.

Very bizarre error that I can't figure out.

Jason Axelrod
  • 7,155
  • 10
  • 50
  • 78

1 Answers1

0

Issue solved! The event was getting triggered when the form was initializing, but saveButton was not initialized yet. I removed the default values of the field and all is well.

Jason Axelrod
  • 7,155
  • 10
  • 50
  • 78
  • Hey man. I know this answer was posted a long time ago, but what values did you remove to get it working? I'm having the same issues at the moment. – CareTaker22 Apr 03 '16 at 10:08