RibbonControlsLibrary - how to disable minimizing?

柔情痞子 提交于 2019-12-06 06:46:26

问题


How to disable minimizing of Ribbon control from RibbonControlsLibrary?


回答1:


The following disabled both the double click on the tab header and 'Minimize the Ribbon' on the context menu for me:

public class ExRibbon : Ribbon
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        IsMinimizedProperty.OverrideMetadata(typeof(ExRibbon),
                new FrameworkPropertyMetadata(false, (o, e) => { }, (o, e) => false));

        Type ownerType = typeof(ExRibbon);
        CommandManager.RegisterClassCommandBinding(ownerType,
            new CommandBinding(RibbonCommands.MinimizeRibbonCommand, null, MinimizeRibbonCanExecute));
    }

    private static void MinimizeRibbonCanExecute(object sender, CanExecuteRoutedEventArgs args)
    {
        args.CanExecute = false;
        args.Handled = true;
    }
}



回答2:


public class ExRibbon : Ribbon
{
    public override void OnApplyTemplate()
    {
         base.OnApplyTemplate();

         if (!IsMinimizable)
         {
              IsMinimizedProperty.OverrideMetadata(typeof(ExRibbon), 
                   new FrameworkPropertyMetadata(false, (o, e) => { }, (o,e) => false));
         }
    }
    public bool IsMinimizable { get; set; }
}



回答3:


The only way that minimices the control and can't be disabled is a double click on a Tab header, in fact a triple click or more than 2 clicks also minimices the control, this is why my first idea failed (I tryed to cancel the double click event, but the control minimized on the third click).

SO this solution isn't too prety but it works fine, when more than two clicks are detected on the TabHeaderItemsControl (this is the control that holds the tabs) then the control is maximized

public class MinimizableRibbon : Ribbon
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        RibbonTabHeaderItemsControl tabItems = this.FindName("TabHeaderItemsControl") as RibbonTabHeaderItemsControl;

        int lastClickTime = 0;
        if (tabItems != null)
            tabItems.PreviewMouseDown += (_, e) =>
                {
                    // A continuous click was made (>= 2 clicks minimizes the control)
                    if (Environment.TickCount - lastClickTime < 300)
                        // here the control should be minimized
                        if (!IsMinimizable)
                            IsMinimized = false;

                    lastClickTime=Environment.TickCount;
                };
    }

    public bool IsMinimizable { get; set; }
}


来源:https://stackoverflow.com/questions/7412853/ribboncontrolslibrary-how-to-disable-minimizing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!