viewmodel - INotifyDataErrorInfo reusable methods -


I am using MVVM-Light and for each visual model, I have to implement INotifyDataErrorInfo which is similar in some cases Uses ways to validate the same property types In this example, I am using date time:

  using the system; Using System.Collections.Generic; Using System.ComponentModel; Using SL.Resources; Namespace SL.ViewModel {public partial class AdministrationViewModel: INotifyDataErrorInfo {#region verification public void isDateToValid (? Datetime value DATETIME, dateFrom, string property) {// check if null if (value == null) AddError (property, CommonErrors .DateNull_ERROR, False); Else RemoveError (propertyName, CommonErrors.DateNull_ERROR); // If the minimum and check the maximum value (value & lt; DateTime.MinValue || value & gt; DateTime.MaxValue) AddError (property, CommonErrorskDateNotValid_ERROR, false); Else RemoveError (propertyName, CommonErrors.DateNotValid_ERROR); If (value & lt; dateFrom) addError (propertyName, CommonErrors.DateFromSmall_ERROR, incorrect); Else RemoveError (propertyName, CommonErrors.DateFromSmall_ERROR); } Public Zero IsDateValid (date time? Value, string propertyName) {if (value == zero) addError (propertyName, CommonErrors.DateNull_ERROR, incorrect); Else RemoveError (propertyName, CommonErrors.DateNull_ERROR); If (value> dateTime.MinValue || value & gt; datetime.maxvalue) addError (propertyName, CommonErrors.DateNotValid_ERROR, incorrect); Else RemoveError (propertyName, CommonErrors.DateNotValid_ERROR); } #endrian #region INotifyDataErrorInfo Member Public Dictionary & lt; String, list & lt; String & gt; & Gt; Errors = New Dictionary & lt; String, list & lt; String & gt; & Gt; (); // Errors add the specified error to the archive If this // is not already present, then if it is warned to put it in the first place // false. Changes the collection if the change varies. Public void AddError (String Property name, string error, the bool warning) {if (! Errors. Kantn (Property name) Errors [propertyName] = new List & lt; String & gt; (); if (! Errors [propertyName]. Kanslton (error)) {if (Hacinging) errors [propertyName]. Add (error); other errors [propertyName] .asrt (0, error); RaiseErrorsChanged (property);}} // error removes the specified error collection If it is present // changes the archive changes And shift changes. Public void RemoveError (String propertyName, string error) {if (errors.ContainsKey (propertyName) & amp; amp; and [propertiesName] errors. (Error)) {errors [propertyName]. Delete (error); If (errors [propertyName]. Count == 0) errors.Remove (propertyName); RaiseErrorsChanged (property);}} public void RaiseErrorsChanged (string propertyName) {if (ErrorsChanged! = null) errors change (this, new DataErrorsChangedEventArgs (propertyName ));} Public Event System.EventHandler & lt; DatacentersCongressEventErgies & gt; ErrorsChanged; Public system compilation. Inexorable GetErrors (string propertyName) {if (string.IsNullOrEmptE (propertyName) ||! Errors. Associates key (propertyName)) Return tap; Return errors [propertyName]; } Public Hair Hairs {Get {Return Errors} Account & gt; 0; }} #endregion}}   

How can I make this scene re-usable in other visual models, so I do not need to implement the same thing over and over again is?

I created a class that applies the INotifyDataErrorInfo:

  public class ViewModelValidation: INotifyDataErrorInfo   

but when I I do not want to be used in this model:

  Public partial class administration ViewModel: ViewModelValidation   

Error:

  Declarations of partial 'SL.ViewModel.AdministrationViewModel' should not be specified in different base classes ...   

That's because my main view model is I have a base class with MVVM-Light:

Public partial class administration ViewModel: ViewModelBase

Any help in solving this is appretiated.

itemprop = "text">

I understood it myself, I have a ViewModelCommon ViewModelBase On the basis of MVVM Lite, the class is created and the INotifyDataErrorInfo interface said in it:

  Public class ViewModelCommon: ViewModelBase, INotifyDataErrorInfo   

then instead of ViewModelBase < / Code> I used my ViewModelCommon class in my idea model code:

  public partial category administration viewModel: seeModelCommission   

And this Works fine.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -