I’m building a Windows Store App and I have a TextBox binded (two-way mode) to a string “title” property of my TaskItem object.
I need to do some processing after changes in the UI are made to this TextBox and propagated back to the source.
I’d like to know if there’s a way to detect when the target (TextBox’s Text property) has changed. I know I can catch this event by handling the TextBox’s LostFocus event, but this event is triggered before the source is updated.
Update:
Binding:
<ScrollViewer
x:Name="itemDetail"
DataContext="{Binding SelectedItem, ElementName=itemListView}">
<TextBox x:Name="itemTitle" Text="{Binding Title, Mode=TwoWay}"/>
</ScrollViewer>
Class and property:
class TaskItem
{
public string Title { get; set; }
}
I didn’t implement the INotifyPropertyChanged because I actually don’t need changes to be propagated from the source to the target.
I can think of two solutions:
- Is there a way to use [CallerMemberName] on a property’s setter? If there is, I may be able to determine whether the “title” was changed by my own code or because of the binding.
- Ditch the two-way binding and update the source manually during the LostFocus event.
Constructor Design