RaisePropertyChanged() protected méthode

Raises the property changed.
protected RaisePropertyChanged ( Func lazyEAFactory ) : void
lazyEAFactory Func The lazy ea factory.
Résultat void
            /// <summary>
            /// Internals the property change.
            /// </summary>
            /// <param name="objectInstance">The object instance.</param>
            /// <param name="newValue">The new value.</param>
            /// <param name="currentValue">The current value.</param>
            /// <param name="message">The message.</param>
            private void InternalPropertyChange(BindableBase objectInstance, TProperty newValue, ref TProperty currentValue, string message)
            {
                var changing = (this.EqualityComparer != null) ?
                               !this.EqualityComparer(newValue, currentValue) :
                               !Object.Equals(newValue, currentValue);


                if (changing)
                {
                    var oldvalue = currentValue;
                    currentValue = newValue;

                    ValueChangedEventArgs <TProperty> arg = null;

                    Func <PropertyChangedEventArgs> lzf =
                        () =>
                    {
                        arg = arg ?? new ValueChangedEventArgs <TProperty>(message, oldvalue, newValue);
                        return(arg);
                    };


                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(message));
                    objectInstance.RaisePropertyChanged(lzf);
                    ValueChanged?.Invoke(this, lzf() as ValueChangedEventArgs <TProperty>);
                    ValueChangedWithNameOnly?.Invoke(this, new PropertyChangedEventArgs(message));
                    ValueChangedWithNothing?.Invoke(this, EventArgs.Empty);
                }
            }
Exemple #2
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);
            }