Beispiel #1
0
        protected override void UpdateCanExecute()
        {
            if (Command != null)
            {
                CanExecute = GameCommand.CanExecuteCommandSource(this);
            }
            else
            {
                CanExecute = true;
            }

            var checkableParameter = CommandParameter as ICheckableCommandParameter;

            if ((checkableParameter == null) || !checkableParameter.Handled)
            {
                return;
            }

            IsChecked = checkableParameter.IsChecked;

            checkableParameter.Handled = false;
        }
Beispiel #2
0
        protected override void UpdateCanExecute()
        {
            var commandCanExecute = Command == null || Command == ApplicationCommands.NotACommand || GameCommand.CanExecuteCommandSource(this);

            CanExecute = commandCanExecute && (!AutoDisableWhenPopupContentIsDisabled || (PopupControlService.IsPopupAnchorPopupEnabled(this)));
        }
Beispiel #3
0
        private static bool IsPopupAnchorPopupEnabledRecursive(UIElement element, ref bool isEnabled)
        {
            var validControlFound = false;

            // Check for an items control
            var itemsControl = element as ItemsControl;

            if (itemsControl != null)
            {
                for (var index = 0; index < itemsControl.Items.Count; index++)
                {
                    var childElement = itemsControl.Items[index] as UIElement ??
                                       itemsControl.ItemContainerGenerator.ContainerFromIndex(index) as UIElement;

                    if (childElement == null)
                    {
                        continue;
                    }

                    var gameControl = childElement as IGameControl;
                    if (gameControl == null)
                    {
                        continue;
                    }

                    if (gameControl.Command != null)
                    {
                        // If using ItemsSource, the visual tree may not yet be built so force the parent element as the target
                        if (VisualTreeHelper.GetParent(childElement) == null)
                        {
                            isEnabled = GameCommand.CanExecuteCommandSource(gameControl, element);
                        }
                        else
                        {
                            isEnabled = GameCommand.CanExecuteCommandSource(gameControl);
                        }
                    }
                    else
                    {
                        isEnabled = childElement.IsEnabled;
                    }

                    validControlFound = true;

                    if (isEnabled)
                    {
                        return(true);
                    }
                }
            }

            var children = LogicalTreeHelper.GetChildren(element);

            foreach (var child in children)
            {
                var childElement = child as UIElement;
                if (childElement == null)
                {
                    continue;
                }

                var gameControl = childElement as IGameControl;
                if (gameControl != null)
                {
                    if (gameControl.Command != null)
                    {
                        isEnabled = GameCommand.CanExecuteCommandSource(gameControl);
                    }
                    else
                    {
                        isEnabled = childElement.IsEnabled;
                    }

                    validControlFound = true;

                    if (isEnabled)
                    {
                        return(true);
                    }
                }

                if ((childElement is IGamePopupAnchor))
                {
                    continue;
                }

                // Recurse and quit afterwards if an enabled
                validControlFound |= IsPopupAnchorPopupEnabledRecursive(childElement, ref isEnabled);

                if (isEnabled)
                {
                    return(validControlFound);
                }
            }

            return(validControlFound);
        }