Пример #1
0
        public static bool SetPropertyValue <TProperty>(
            IModel model,
            ref TProperty property,
            TProperty value,
            string propertyName)

        {
            IModelOptions options = model.ModelOptions ?? ModelOptions.Default;

            if (options.UseOnlyOnPropertyChanged)
            {
                property = value;
                model.OnPropertyChanged(propertyName);
                return(true);
            }

            if (property == null & value == null)
            {
                return(true);
            }
            else if (property != null && property.Equals(value))
            {
                return(true);
            }

            TProperty oldValue = property;

            property = value;

            if (options.UseOnVerification)
            {
                var args = new MvvmElementPropertyVerifyChangeEventArgs(propertyName);
                model.OnVerification(args);
                if (!args.IsValid)
                {
                    property = oldValue;
                    model.OnErrors(args.GetErrors());
                    return(false);
                }
            }
            if (options.UseVerifyPropertyChange && !model.OnVerifyPropertyChange(propertyName))
            {
                property = oldValue;
                return(false);
            }

            model.OnPropertyChanged(propertyName);
            return(true);
        }
Пример #2
0
        public static bool OnVerifyPropertyChange(IModel element, Action <MvvmElementPropertyVerifyChangeEventArgs> onVerifyPropertyChange, string propertyName)
        {
            var options = element.ModelOptions ?? ModelOptions.Default;

            if (!options.UseVerifyPropertyChange)
            {
                return(false);
            }

            var args = new MvvmElementPropertyVerifyChangeEventArgs(propertyName);

            onVerifyPropertyChange(args);

            if (!args.IsValid)
            {
                element.OnErrors(args.GetErrors());
            }

            return(args.IsValid);
        }
Пример #3
0
 /// <summary>
 /// Verification hendler
 /// </summary>
 /// <param name="e"></param>
 public virtual void OnVerification(MvvmElementPropertyVerifyChangeEventArgs e)
 {
 }