Beispiel #1
0
        /// <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
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Adds a new entry to the list of dependent property notifications.
        /// </summary>
        /// <typeparam name="TSource">the type of the source property</typeparam>
        /// <typeparam name="TDepend">the type of the dependent property</typeparam>
        public virtual void AddPropertyChangedNotification <TSource, TDepend>(
            Expression <Func <TSource> > sourcePropertyAccessor,
            params Expression <Func <TDepend> >[] dependentPropertyAccessors)
        {
            var basePropertyName = GetPropertyName(sourcePropertyAccessor);

            foreach (var dependentPropertyName in dependentPropertyAccessors
                     .Select(GetPropertyName)
                     .Where(dependentPropertyName => basePropertyName != dependentPropertyName))
            {
                if (!DependentNotifications.TryGetValue(basePropertyName, out var notifications))
                {
                    notifications = new List <string>();
                    DependentNotifications.Add(basePropertyName, notifications);
                }

                notifications.Add(dependentPropertyName);
            }
        }