Inheritance: System.Windows.Controls.ContextMenu
コード例 #1
0
        private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonContextMenu contextMenu = (RibbonContextMenu)d;

            if (!(bool)(e.NewValue))
            {
                if (!contextMenu._ignoreDismissPopupsOnNextClose)
                {
                    UIElement dismissPopupSource = contextMenu.GetDismissPopupSource();
                    if (CanRaiseDismissPopups(dismissPopupSource))
                    {
                        // Raise DismissPopup on owner if can raise and if
                        // was not asked to ignore.
                        dismissPopupSource.RaiseEvent(new RibbonDismissPopupEventArgs(RibbonDismissPopupMode.Always));
                        ((Ribbon)(RibbonControlService.GetRibbon(dismissPopupSource))).RestoreFocusOnContextMenuClose();
                    }
                }
                else
                {
                    contextMenu.RestoreFocusToRibbon();
                    contextMenu._ignoreDismissPopupsOnNextClose = false;
                }
            }
            else
            {
                contextMenu._ignoreDismissPopupsOnNextClose = false;
            }
        }
コード例 #2
0
        private static RibbonMenuItem GenerateQATPlacementMenuItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem qatPlacementItem = new RibbonMenuItem()
            {
                CanAddToQuickAccessToolBarDirectly = false
            };

            Binding headerBinding = new Binding("PlacementTarget")
            {
                Source = contextMenu
            };

            headerBinding.Converter = new PlacementTargetToQATPositionConverter(PlacementTargetToQATPositionConverter.ConverterMode.Header);
            qatPlacementItem.SetBinding(RibbonMenuItem.HeaderProperty, headerBinding);

            Binding commandBinding = new Binding("PlacementTarget")
            {
                Source = contextMenu
            };

            commandBinding.Converter = new PlacementTargetToQATPositionConverter(PlacementTargetToQATPositionConverter.ConverterMode.Command);
            qatPlacementItem.SetBinding(RibbonMenuItem.CommandProperty, commandBinding);

            Binding placementTargetBinding = new Binding("PlacementTarget")
            {
                Source = contextMenu
            };

            qatPlacementItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);

            return(qatPlacementItem);
        }
コード例 #3
0
        private static RibbonContextMenu GetGalleryContextMenu()
        {
            if (_galleryContextMenu == null)
            {
                _galleryContextMenu = new RibbonContextMenu();
                RibbonMenuItem addGalleryToQATItem = GenerateAddGalleryToQATItem(_galleryContextMenu);
                _galleryContextMenu.Items.Add(addGalleryToQATItem);
            }

            return(_galleryContextMenu);
        }
コード例 #4
0
        private static RibbonContextMenu GetDefaultRibbonClientAreaContextMenu()
        {
            if (_defaultRibbonClientAreaContextMenu == null)
            {
                _defaultRibbonClientAreaContextMenu = new RibbonContextMenu();
                _defaultRibbonClientAreaContextMenu.Items.Add(GenerateQATPlacementMenuItem(_defaultRibbonClientAreaContextMenu));
                _defaultRibbonClientAreaContextMenu.Items.Add(new RibbonSeparator());
                _defaultRibbonClientAreaContextMenu.Items.Add(GenerateMinimizeTheRibbonItem(_defaultRibbonClientAreaContextMenu));
            }

            return(_defaultRibbonClientAreaContextMenu);
        }
コード例 #5
0
        private static RibbonContextMenu GetQATControlContextMenu()
        {
            if (_qatControlContextMenu == null)
            {
                _qatControlContextMenu = new RibbonContextMenu();
                _qatControlContextMenu.Items.Add(GenerateAddToOrRemoveFromQATItem(true, _qatControlContextMenu));
                _qatControlContextMenu.Items.Add(new RibbonSeparator());
                _qatControlContextMenu.Items.Add(GenerateQATPlacementMenuItem(_qatControlContextMenu));
                _qatControlContextMenu.Items.Add(new RibbonSeparator());
                _qatControlContextMenu.Items.Add(GenerateMinimizeTheRibbonItem(_qatControlContextMenu));
            }

            return(_qatControlContextMenu);
        }
コード例 #6
0
        private static RibbonMenuItem GenerateAddGalleryToQATItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem addGalleryToQATItem = new RibbonMenuItem();

            addGalleryToQATItem.Header = _addGalleryToQATText;

            // Even for galleries in QAT, this menu item always binds the "add to QAT" command.
            addGalleryToQATItem.Command = RibbonCommands.AddToQuickAccessToolBarCommand;

            Binding placementTargetBinding = new Binding("PlacementTarget")
            {
                Source = contextMenu
            };

            addGalleryToQATItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);

            return(addGalleryToQATItem);
        }
コード例 #7
0
        private static RibbonMenuItem GenerateMinimizeTheRibbonItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem minimizeTheRibbonItem = new RibbonMenuItem()
            {
                CanAddToQuickAccessToolBarDirectly = false
            };

            minimizeTheRibbonItem.Header = MinimizeTheRibbonText;

            PropertyPath path = new PropertyPath("(0).(1).(2)");

            path.PathParameters.Add(ContextMenuService.PlacementTargetProperty);
            path.PathParameters.Add(RibbonControlService.RibbonProperty);
            path.PathParameters.Add(Ribbon.IsMinimizedProperty);

            Binding isCheckedBinding = new Binding()
            {
                Source = contextMenu, Path = path
            };

            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.IsCheckedProperty, isCheckedBinding);
            Binding isMinimizedBinding = new Binding()
            {
                Source = contextMenu, Path = path
            };

            isMinimizedBinding.Converter = new IsMinimizedToMinimizeOrMaximizeCommandConverter();
            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.CommandProperty, isMinimizedBinding);
            Binding placementTargetBinding = new Binding("PlacementTarget")
            {
                Source = contextMenu
            };

            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);
            return(minimizeTheRibbonItem);
        }
コード例 #8
0
        private static RibbonContextMenu GetRibbonControlContextMenu()
        {
            if (_ribbonControlContextMenu == null)
            {
                _ribbonControlContextMenu = new RibbonContextMenu();
                _ribbonControlContextMenu.Items.Add(GenerateAddToOrRemoveFromQATItem(false, _ribbonControlContextMenu));
                _ribbonControlContextMenu.Items.Add(new RibbonSeparator());
                _ribbonControlContextMenu.Items.Add(GenerateQATPlacementMenuItem(_ribbonControlContextMenu));
                _ribbonControlContextMenu.Items.Add(new RibbonSeparator());
                _ribbonControlContextMenu.Items.Add(GenerateMinimizeTheRibbonItem(_ribbonControlContextMenu));
            }

            return _ribbonControlContextMenu;
        }
コード例 #9
0
        private static RibbonContextMenu GetGalleryContextMenu()
        {
            if (_galleryContextMenu == null)
            {
                _galleryContextMenu = new RibbonContextMenu();
                RibbonMenuItem addGalleryToQATItem = GenerateAddGalleryToQATItem(_galleryContextMenu);
                _galleryContextMenu.Items.Add(addGalleryToQATItem);
            }

            return _galleryContextMenu;
        }
コード例 #10
0
        private static RibbonContextMenu GetDefaultRibbonClientAreaContextMenu()
        {
            if (_defaultRibbonClientAreaContextMenu == null)
            {
                _defaultRibbonClientAreaContextMenu = new RibbonContextMenu();
                _defaultRibbonClientAreaContextMenu.Items.Add(GenerateQATPlacementMenuItem(_defaultRibbonClientAreaContextMenu));
                _defaultRibbonClientAreaContextMenu.Items.Add(new RibbonSeparator());
                _defaultRibbonClientAreaContextMenu.Items.Add(GenerateMinimizeTheRibbonItem(_defaultRibbonClientAreaContextMenu));
            }

            return _defaultRibbonClientAreaContextMenu;
        }
コード例 #11
0
        private static RibbonMenuItem GenerateQATPlacementMenuItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem qatPlacementItem = new RibbonMenuItem() { CanAddToQuickAccessToolBarDirectly = false };

            Binding headerBinding = new Binding("PlacementTarget") { Source = contextMenu };
            headerBinding.Converter = new PlacementTargetToQATPositionConverter(PlacementTargetToQATPositionConverter.ConverterMode.Header);
            qatPlacementItem.SetBinding(RibbonMenuItem.HeaderProperty, headerBinding);

            Binding commandBinding = new Binding("PlacementTarget") { Source = contextMenu };
            commandBinding.Converter = new PlacementTargetToQATPositionConverter(PlacementTargetToQATPositionConverter.ConverterMode.Command);
            qatPlacementItem.SetBinding(RibbonMenuItem.CommandProperty, commandBinding);

            Binding placementTargetBinding = new Binding("PlacementTarget") { Source = contextMenu };
            qatPlacementItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);

            return qatPlacementItem;
        }
コード例 #12
0
        private static RibbonMenuItem GenerateMinimizeTheRibbonItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem minimizeTheRibbonItem = new RibbonMenuItem() { CanAddToQuickAccessToolBarDirectly = false };
            minimizeTheRibbonItem.Header = MinimizeTheRibbonText;

            PropertyPath path = new PropertyPath("(0).(1).(2)");
            path.PathParameters.Add(ContextMenuService.PlacementTargetProperty);
            path.PathParameters.Add(RibbonControlService.RibbonProperty);
            path.PathParameters.Add(Ribbon.IsMinimizedProperty);

            Binding isCheckedBinding = new Binding () { Source = contextMenu, Path = path };
            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.IsCheckedProperty, isCheckedBinding);
            Binding isMinimizedBinding = new Binding() { Source = contextMenu, Path = path };
            isMinimizedBinding.Converter = new IsMinimizedToMinimizeOrMaximizeCommandConverter();
            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.CommandProperty, isMinimizedBinding);
            Binding placementTargetBinding = new Binding("PlacementTarget") { Source = contextMenu };
            minimizeTheRibbonItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);
            return minimizeTheRibbonItem;
        }
コード例 #13
0
        private static RibbonMenuItem GenerateAddToOrRemoveFromQATItem(bool controlIsInQAT, RibbonContextMenu contextMenu)
        {
            RibbonMenuItem addToOrRemoveFromQATItem = new RibbonMenuItem() { CanAddToQuickAccessToolBarDirectly = false };

            if (controlIsInQAT)
            {
                addToOrRemoveFromQATItem.Header = RemoveFromQATText;
                addToOrRemoveFromQATItem.Command = RibbonCommands.RemoveFromQuickAccessToolBarCommand;
            }
            else
            {
                addToOrRemoveFromQATItem.Header = AddToQATText;
                addToOrRemoveFromQATItem.Command = RibbonCommands.AddToQuickAccessToolBarCommand;
            }

            Binding placementTargetBinding = new Binding("PlacementTarget") { Source = contextMenu };
            addToOrRemoveFromQATItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);

            return addToOrRemoveFromQATItem;
        }
コード例 #14
0
        private static RibbonMenuItem GenerateAddGalleryToQATItem(RibbonContextMenu contextMenu)
        {
            RibbonMenuItem addGalleryToQATItem = new RibbonMenuItem();

            addGalleryToQATItem.Header = _addGalleryToQATText;

            // Even for galleries in QAT, this menu item always binds the "add to QAT" command.
            addGalleryToQATItem.Command = RibbonCommands.AddToQuickAccessToolBarCommand;

            Binding placementTargetBinding = new Binding("PlacementTarget") { Source = contextMenu };
            addGalleryToQATItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);

            return addGalleryToQATItem;
        }
コード例 #15
0
 public RibbonContextMenuAutomationPeer(RibbonContextMenu owner)
     : base(owner)
 {
 }
コード例 #16
0
        private static RibbonMenuItem GenerateAddToOrRemoveFromQATItem(bool controlIsInQAT, RibbonContextMenu contextMenu)
        {
            RibbonMenuItem addToOrRemoveFromQATItem = new RibbonMenuItem()
            {
                CanAddToQuickAccessToolBarDirectly = false
            };

            if (controlIsInQAT)
            {
                addToOrRemoveFromQATItem.Header  = RemoveFromQATText;
                addToOrRemoveFromQATItem.Command = RibbonCommands.RemoveFromQuickAccessToolBarCommand;
            }
            else
            {
                addToOrRemoveFromQATItem.Header  = AddToQATText;
                addToOrRemoveFromQATItem.Command = RibbonCommands.AddToQuickAccessToolBarCommand;
            }

            Binding placementTargetBinding = new Binding("PlacementTarget")
            {
                Source = contextMenu
            };

            addToOrRemoveFromQATItem.SetBinding(RibbonMenuItem.CommandTargetProperty, placementTargetBinding);

            return(addToOrRemoveFromQATItem);
        }