예제 #1
0
 protected bool SetValueUncancellable <T>(ref T field, T value, Action updateAction, [ItemNotNull, NotNull] params string[] propertyNames)
 {
     foreach (var propertyName in propertyNames)
     {
         uncancellableChanges.Add(propertyName);
         string[] dependentProperties;
         if (DependentProperties.TryGetValue(propertyName, out dependentProperties))
         {
             dependentProperties.ForEach(x => uncancellableChanges.Add(x));
         }
     }
     try
     {
         var result = SetValue(ref field, value, updateAction, false, propertyNames);
         return(result);
     }
     finally
     {
         foreach (var propertyName in propertyNames)
         {
             uncancellableChanges.Remove(propertyName);
             string[] dependentProperties;
             if (DependentProperties.TryGetValue(propertyName, out dependentProperties))
             {
                 dependentProperties.ForEach(x => uncancellableChanges.Remove(x));
             }
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Manages a property modification and its notifications. A function is provided to check whether the new value is different from the current one.
 /// This function will be invoked by this method, and if it returns <c>True</c>, it will invoke the provided update action. The <see cref="ViewModelBase.PropertyChanging"/>
 /// event will be raised prior to the update action, and the <see cref="ViewModelBase.PropertyChanged"/> event will be raised after.
 /// </summary>
 /// <remarks>This method does not register <see cref="IActionItem"/> into the associated <see cref="ITransactionalActionStack"/>.</remarks>
 /// <param name="hasChangedFunction">A function that check if the new value is different and therefore if the update must be actually done.</param>
 /// <param name="updateAction">The update action that will actually manage the update of the property.</param>
 /// <param name="propertyNames">The names of the properties that must be notified as changing/changed. At least one property name must be provided.</param>
 /// <returns><c>True</c> if the update was done and events were raised, <c>False</c> if <see cref="hasChangedFunction"/> is not <c>null</c> and returned false.</returns>
 protected virtual bool SetValueUncancellable(Func <bool> hasChangedFunction, Action updateAction, params string[] propertyNames)
 {
     foreach (var propertyName in propertyNames)
     {
         uncancellableChanges.Add(propertyName);
         string[] dependentProperties;
         if (DependentProperties.TryGetValue(propertyName, out dependentProperties))
         {
             dependentProperties.ForEach(x => uncancellableChanges.Add(x));
         }
     }
     try
     {
         var result = SetValue(hasChangedFunction, updateAction, propertyNames);
         return(result);
     }
     finally
     {
         foreach (var propertyName in propertyNames)
         {
             uncancellableChanges.Remove(propertyName);
             string[] dependentProperties;
             if (DependentProperties.TryGetValue(propertyName, out dependentProperties))
             {
                 dependentProperties.ForEach(x => uncancellableChanges.Remove(x));
             }
         }
     }
 }