Exemple #1
0
        protected override bool SetProperty <T>(ref T fieldValue, T newValue, [CallerMemberName] string propertyName = null)
        {
            if ((fieldValue as FlowDocument) != null && (newValue as FlowDocument) != null)
            {
                TextRange oldDoc = new TextRange((fieldValue as FlowDocument).ContentStart, (fieldValue as FlowDocument).ContentEnd);
                TextRange newDoc = new TextRange((newValue as FlowDocument).ContentStart, (newValue as FlowDocument).ContentEnd);
                if (oldDoc.GetHashCode() == newDoc.GetHashCode())
                {
                    return(false);
                }
            }
            else if (EqualityComparer <T> .Default.Equals(fieldValue, newValue))
            {
                return(false);
            }

            // change tracking support
            if (TrackChanges == true)
            {
                StoreInitialValue(fieldValue, propertyName);

                // updatedDateTime support
                StoreInitialValue(_updatedDateTime, nameof(UpdatedDateTime));
                // update updatedDateTime when every other property change
                if (propertyName != "UpdatedDateTime")
                {
                    _updatedDateTime = DateTime.Now;
                }
                RaisePropertyChanged(nameof(UpdatedDateTime));
            }

            fieldValue = newValue;
            RaisePropertyChanged(propertyName);

            return(true);
        }