/// <summary>
        /// Adds the provider command to the command view (this might not add it or move it to a new structure)
        /// </summary>
        /// <param name="providerCommandItem">The provider command item.</param>
        /// <param name="commandView">The command view.</param>
        public virtual void AddProviderCommand(ICommandItem providerCommandItem, ICommandProvider commandView)
        {
            if (providerCommandItem == null)
            {
                throw new ArgumentNullException(@"providerCommandItem");
            }

            if (commandView == null)
            {
                throw new ArgumentNullException(@"commandView");
            }

            if (providerCommandItem.ParentCommand != null)
            {
                var parentCommandInView = commandView.FindCommand(providerCommandItem.ParentCommand.Id);

                if (parentCommandInView != null)
                {
                    parentCommandInView.AddCommand(providerCommandItem);
                    return;
                }
            }

            commandView.AddCommand(providerCommandItem);
        }
Example #2
0
        private void SubscribeCanExecuteCommandInternal(NotificationReflectorModel model, string propertyName, ICommand command, Func <string, bool> raiseFunc)
        {
            var guaranteedCommandName = model.GetKeyCommand(propertyName);

            _cmdProvider.AddCommand(guaranteedCommandName, command);

            CommandChangedEventHandler handler = (objectSender, commandName) =>
            {
                var result = raiseFunc.Invoke(commandName);

                if (!result)
                {
                    raiseFunc.Invoke(guaranteedCommandName);
                }
            };

            model.CanExecuteCommandChanged += handler;

            _subscribersDictionary.Add(guaranteedCommandName, handler);
        }