RibbonControlsLibrary - how to disable minimizing?

2019-04-11 16:26发布

How to disable minimizing of Ribbon control from RibbonControlsLibrary?

3条回答
Juvenile、少年°
2楼-- · 2019-04-11 16:39

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;
    }
}
查看更多
劫难
3楼-- · 2019-04-11 16:51

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; }
}
查看更多
别忘想泡老子
4楼-- · 2019-04-11 16:57
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; }
}
查看更多
登录 后发表回答