The problem is that you are updating the source for Binding , and Binding updating your property. WPF does not actually check your property value when it raises the PropertyChanged event in response to a Binding update. You can solve this problem by using Dispatcher to delay the propagation of events in this thread:
set { int val = int.Parse(value); if (_runAfter != val) { if (val < _order) { _runAfter = val; OnPropertyChanged("RunAfter"); } else { _runAfter = 0; Dispatcher.CurrentDispatcher.BeginInvoke( new Action<String>(OnPropertyChanged), DispatcherPriority.DataBind, "RunAfter"); } } }
Update:
I noticed that Binding on your TextBox uses the default UpdateSourceTrigger , which happens when the TextBox loses focus. You will not see the text change to 0 until the TextBox loses focus with this mode. If you change it to PropertyChanged , you will see that this happens immediately. Otherwise, your property will not be set until your TextBox loses focus:
<TextBox Name="txtRunAfter" Grid.Column="4" Text="{Binding RunAfter, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource TestStepTextBox}"/>
Abe heidebrecht
source share