/// <summary> /// Raises this object's PropertyChanged event. /// </summary> private void RaisePropertyChanged(string propertyName, bool notifyDependentProperties, IDictionary <string, object> processedProperties, IDictionary <ICommand, object> processedCommands) { if (processedProperties.ContainsKey(propertyName)) { return; } var eventArgs = new PropertyChangedEventArgs(propertyName); if (PropertyChanged != null) { Dispatch(() => PropertyChanged(this, eventArgs)); } // ReSharper disable AssignNullToNotNullAttribute processedProperties.Add(propertyName, null); // ReSharper restore AssignNullToNotNullAttribute if (!notifyDependentProperties) { return; } if (DependentNotifications.TryGetValue(propertyName, out var dependentPropertyNotifications)) { foreach (var dependentProperty in dependentPropertyNotifications) { RaisePropertyChanged(dependentProperty, true, processedProperties, processedCommands); } } if (DependentCommandNotifications.TryGetValue(propertyName, out var dependendCommandNotifications)) { foreach (var dependentCommand in dependendCommandNotifications) { if (processedCommands.ContainsKey(dependentCommand)) { continue; } if (dependentCommand is RelayCommand relayCommand) { relayCommand.RaiseCanExecuteChanged(); } // ReSharper disable AssignNullToNotNullAttribute processedCommands.Add(dependentCommand, null); // ReSharper restore AssignNullToNotNullAttribute } } }
/// <summary> /// Adds the dependent notification. /// </summary> /// <param name="basePropertyName">Name of the base property.</param> /// <param name="dependendCommands">The dependend commands.</param> public virtual void AddPropertyChangedNotification(string basePropertyName, params ICommand[] dependendCommands) { IList <ICommand> notifications; if (DependentCommandNotifications.ContainsKey(basePropertyName)) { notifications = DependentCommandNotifications[basePropertyName]; } else { notifications = new List <ICommand>(); DependentCommandNotifications.Add(basePropertyName, notifications); } foreach (var notification in dependendCommands.Except(notifications)) { notifications.Add(notification); } }