forum

Home / DeveloperSection / Forums / NullReferenceException on String Property

NullReferenceException on String Property

Anonymous User 2031 21-Sep-2013

In my program I allow the user to add to a Data Collection bound to a TreeView. When the user creates the new node they are allowed to assign it a name. The user writes the nodes name in a textBox located in a pop up window. The text from the text box is bound to a property in a ViewModel.

However, I can't seem to get the property or the string in the ViewModel to read the value that it is bound to. It just shows up in the debugger as null, which is when I get the exception. I've created other windows exactly like this, but for some reason this one doesn't want to work.

XAML:

<TextBox Text="{Binding TransName}" MaxHeight="20" MinHeight="20" Height="20" Margin="142,24,12,40" Name="textBox1" TextChanged="textBox1_TextChanged"></TextBox>

In the View Model:

private string _nodeName;

//Property for Node Name

public string NodeName

{

     get { return _nodeName; }

     set

     {

         _nodeName = value;

         NotifyPropertyChange(() => NodeName);

     }

}

Still in the View Model, this is the line in which the Exception occurs

//hasSpace is a boolean

hasSpace = _nodeName.Contains(" ");


wpf
Updated on 21-Sep-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By