2016-11-20 21 views

回答

1

Prism.Wpf中的驗證通過執行IDataErrorInfoINotifyDataErrorInfo接口完成。舉例:

public abstract class DomainObject : INotifyPropertyChanged, INotifyDataErrorInfo 
{ 
    private ErrorsContainer<ValidationResult> errorsContainer = 
        new ErrorsContainer<ValidationResult>(
         pn => this.RaiseErrorsChanged(pn)); 

    public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged; 

    public bool HasErrors 
    { 
     get { return this.ErrorsContainer.HasErrors; } 
    } 

    public IEnumerable GetErrors(string propertyName) 
    { 
     return this.errorsContainer.GetErrors(propertyName); 
    } 

    protected void RaiseErrorsChanged(string propertyName) 
    { 
     var handler = this.ErrorsChanged; 
     if (handler != null) 
     { 
      handler(this, new DataErrorsChangedEventArgs(propertyName)); 
     } 
    } 
    ... 
} 

這也在Prism的documentation中解釋過。

那麼爲什麼UWP不這樣工作呢?因爲在UWP上,您無法訪問這些接口,因此需要ValidatableBindableBaseBindableValidator類。如果出於某種原因,您喜歡這種方法,則無法阻止您將UWP課程帶入您的WPF解決方案,所有代碼均爲open source

+0

BindableValidator有 var resourceLoader = ResourceLoader.GetForCurrentView(mapId); 這將取代什麼? –

相關問題