Note that there are some explanatory texts on larger screens.

plurals
  1. POPropertyChangedEvent and CanExecute issue
    text
    copied!<p>I am using MVVM (prism) to develop wpf application. </p> <p>One of my model class "StandardContact" has its properties directly bound to the view. I use IDataErrorInfo to track and notify whether the model has any error. If there are any errors in Model, I disable the "Save" Command. </p> <p>As the user enters some data, I use the StandardContact.PropertyChanged handler to see if "Save" command can execute (i.e if the model data entered by user is valid). The problem is that the StandardContact.PropertyChanged handler is called before the IDataErrorInfo's validation code, so CanExecute for "Save" command does not correctly reflect whether the command can be executed or not. What I am looking for is that, before the CanExecute executes, the IDataErrorInfo validation should run so that the CanExecute will query on the latest data in model and decide whether it is enabled or not. Here is the sample code that I am using</p> <p>Model:</p> <pre><code>public class StandardContact :EntityBase, IDataErrorInfo { public virtual string Name { get { return _name; } set { SetField(ref _name, value, () =&gt; Name); } } //... //Validators public string this[string propertyName] { get { string error = null; //.... } </code></pre> <p>ViewModel</p> <pre><code>public class SContactEditViewModel : NotificationObject, INavigationAware { //.... StandardContact.PropertyChanged += new PropertyChangedEventHandler(StandardContact_PropertyChanged); void StandardContact_PropertyChanged(object sender, PropertyChangedEventArgs e) { //Requery if command can execute SaveNewCommand.RaiseCanExecuteChanged(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload