Exemplo n.º 1
0
            /// <summary>
            /// Internals the property change.
            /// </summary>
            /// <param name="modelInstance">The model instance.</param>
            /// <param name="newValue">The new value.</param>

            /// <param name="message">The message.</param>
            private async void InternalPropertyChange(BindableBase modelInstance, TProperty newValue, string message)
            {
                //find out there will be a changing by makesure they are not equal
                var changing = (this.EqualityComparer != null) ?
                               !this.EqualityComparer(newValue, _value) :
                               !Object.Equals(newValue, _value);

                if (!changing)
                {
                    return;
                }
                //fire changing event ask if anyone against changing

                var changingArg = new ValueChangingEventArgs <TProperty>(message, _value, newValue);

                modelInstance.RaisePropertyChanging(changingArg);
                var oldvalue = _value;

                _value = newValue;

                await Task.Yield();

                if (changingArg.Cancellation.IsCancellationRequested)
                {
                    _value = oldvalue;
                    return;
                }

                if (ValueChanging != null)
                {
                    ValueChanging.Invoke(this, changingArg);
                    await Task.Yield();

                    if (changingArg.Cancellation.IsCancellationRequested)
                    {
                        _value = oldvalue;
                        return;
                    }
                }

                if (NonGenericValueChanging != null)
                {
                    NonGenericValueChanging.Invoke(this, changingArg);
                    await Task.Yield();

                    if (changingArg.Cancellation.IsCancellationRequested)
                    {
                        _value = oldvalue;
                        return;
                    }
                }



                ValueChangedEventArgs <TProperty> changedArg = new ValueChangedEventArgs <TProperty>(message, oldvalue, newValue);

                modelInstance.RaisePropertyChanged(changedArg);
                ValueChanged?.Invoke(this, changedArg);
                NonGenericValueChanged?.Invoke(this, changedArg);
            }