In one of my Data Models I have a string property that is bound to the text of a textBox. When I change the text of this textBox I would like to update a property in another ViewModel. To achieve this, I believe that I would have to perform the operations under the property's setter, but whenever I change the textbox's text the only area of the string property that is called is the getter. There must be something that I don't know or am overlooking..
This is the string property that I am working with just in case it helps to see it:
public string DisplayName
{
get { return _displayName; }
set
{
_displayName = value;
NotifyPropertyChange(() => DisplayName);
//These values are from the other ViewModel
if (MainTreeCollection.SelectedItem != null
&& value != MainTreeCollection.SelectedItem.DisplayName)
MainTreeCollection.SelectedItem.DisplayName = value;
}
}
I noticed in this question he shows how to "get [his] ViewModel to know when the user has changed text in the TextBox and moved the focus away from the TextBox". It looks like he has achieved this by binding to a string property, which is what I did above.
How come the property's setter is not getting accessed? How would I change my method and code to perform these operations?
Update: This is the xaml of the textBox as requested:
<TextBox Text="{Binding Model.DisplayName}" Height="23"
HorizontalAlignment="Left" Name="title_TB"
VerticalAlignment="Top" Width="Auto" FontWeight="Bold"
FontSize="14" Margin="5,2,0,0" />
textBox? - Eric after dark