Beispiel #1
0
        void OnAggregatedObjectHasUnsavedChangesChanged(object sender, EventArgs e)
        {
            TrackableModelBase obj = (TrackableModelBase)sender;

            if (obj.HasUnsavedChanges)
            {
                HasUnsavedChanges = true;
            }
        }
Beispiel #2
0
 public void TrackChanges()
 {
     PropertyChanged += (s, e) =>
     {
         PropertyInfo property = GetType().GetRuntimeProperty(e.PropertyName);
         if (!TrackPropertyChanges(property))
         {
             return;
         }
         HasUnsavedChanges = true;
     };
     foreach (PropertyInfo currentProperty in GetType().GetRuntimeProperties())
     {
         PropertyInfo property = currentProperty;
         if (!typeof(TrackableModelBase).GetTypeInfo().IsAssignableFrom(property.PropertyType.GetTypeInfo()))
         {
             continue;
         }
         if (!TrackPropertyChanges(property))
         {
             continue;
         }
         TrackableModelBase          oldValue = null;
         PropertyChangedEventHandler onAggregatedPropertyChanged = (s, e) =>
         {
             if (e.PropertyName != property.Name)
             {
                 return;
             }
             TrackableModelBase newValue = (TrackableModelBase)property.GetValue(this);
             if (oldValue != null)
             {
                 oldValue.HasUnsavedChangesChanged -= OnAggregatedObjectHasUnsavedChangesChanged;
             }
             if (newValue != null)
             {
                 newValue.HasUnsavedChangesChanged += OnAggregatedObjectHasUnsavedChangesChanged;
             }
             oldValue = newValue;
         };
         PropertyChanged += onAggregatedPropertyChanged;
         onAggregatedPropertyChanged(this, new PropertyChangedEventArgs(property.Name));
     }
 }