Modify your binding's UpdateSourceTrigger to PropertyChanged.
Like so:
<TextBox Name="TitleValue" Text="{Binding ElementName=ListValue,
Path=SelectedItem.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Question
I have the following in my XAML:
<TextBox Name="TitleValue"
Text="{Binding ElementName=ListValue, Path=SelectedItem.Title, Mode=TwoWay}"
<TextBox Name="DescValue"
Text="{Binding ElementName=ListValue,
Path=SelectedItem.Description, Mode=TwoWay}"
When I enter a value in either TitleValue or DescValue and Tab or click on a different location in the window, the collection class properties are updated correctly. Then when I click the X to exit the window, the data in the collection class is saved correctly.
However, when I enter a value in either of those fields, then click X to exit the window, the data in the collection class is saved, but the value entered is not saved for that particular field I was editing when I clicked X.
I implemented a lose focus event on the fields and they work, even when the X is clicked. In those events I put the code:
private void Event_DescValue_LoseFocus(object sender, RoutedEventArgs e)
{
((Import)ListValue.SelectedItem).Description = ((TextBox)e.OriginalSource).Text;
}
But that didn't work either. the following does not work either:
Imports[ListValue.SelectedIndex].Description = ((TextBox)e.OriginalSource).Text;
How do I get the collection class Imports to update the selected class Import when X is clicked when in a field being edited?
It should work exactly like I had Tabbed off the field being edited or clicking elsewhere in the window.
Solution
Modify your binding's UpdateSourceTrigger to PropertyChanged.
Like so:
<TextBox Name="TitleValue" Text="{Binding ElementName=ListValue,
Path=SelectedItem.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>