Наследование: 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);
        }
        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;
        }
        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;
        }
 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);
        }