Beispiel #1
0
        private void TrySetupCommandRelevantProperties()
        {
            var classType = GetType();

            if (commandRelevantProperties.Any(
                    relevance => relevance.Class == classType))
            {
                return;
            }


            var properties = GetPropertiesDecoratedWith <IsRelevantForCommand>(
                classType);

            foreach (var property in properties)
            {
                var attribute = property.GetCustomAttribute <IsRelevantForCommand>();

                if (attribute == null)
                {
                    continue;
                }

                var commandRelevance = new CommandRelevantPropertyWrapper
                {
                    Class        = classType,
                    PropertyName = property.Name,
                    CommandName  = attribute.CommandName
                };


                commandRelevantProperties.Add(
                    commandRelevance);
            }
        }
Beispiel #2
0
        private void UpdateCommandsCanExecute(
            CommandRelevantPropertyWrapper commandRelevance)
        {
            if (commandRelevance == null)
            {
                return;
            }


            if (Options.UseCommandRelevanceAttribute &&
                !string.IsNullOrWhiteSpace(
                    commandRelevance.CommandName))
            {
                var commandProperty = GetCommandProperties()
                                      .FirstOrDefault(
                    property => property.Name == commandRelevance.CommandName);


                if (commandProperty?.GetValue(this) is ICommand command)
                {
                    InvokeCommandCanExecuteChanged(
                        command);

                    return;
                }
            }


            foreach (var property in GetCommandProperties())
            {
                if (!(property.GetValue(this) is ICommand command))
                {
                    continue;
                }


                InvokeCommandCanExecuteChanged(
                    command);
            }
        }