My ViewModel implements the INotifyPropertyChanged and INotifyDataErrorInfo interfaces. When the property is changed, the validation triggers, which in turn enables\disable the Save button.
Because the Validation step is time consuming I've made use of the Delay binding property.
My problem is that I can type my changes and press Save before the 'Name' property is updated.
I'd like to force an immediate update on the TextBox.Text when I press SaveChanges. At the moment, I have to add a sleep before executing to ensure all changes have occurred on the ViewModel.
<TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, Delay=1000}" />
<Button Command="{Binding SaveChanges}" />
Does anyone have some pointers?
Since .NET 4.5 there exists BindingOperations
BindingOperations.GetSourceUpdatingBindings(this).ToList().ForEach(x => x.UpdateSource());
You can implement the IPropertyChanged interface on your viewModel, and then from your Name property setter to check if the value has changed, and raise an OnPropertyChanged event for that property.
You can use that property changed event to wire up your SaveChanges command CanExecute method to return false if not updated yet, and return true if the delay is elapsed and the property is updated.
Therefore, the SaveChanges button stays disabled until the CanExecute returns true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With