RibbonControlsLibrary - 如何禁用最小化?

时间:2011-09-14 07:41:53

标签: c# .net wpf ribboncontrolslibrary

如何从RibbonControlsLibrary中禁用Ribbon控件的最小化?

3 个答案:

答案 0 :(得分:2)

以下功能禁用了双击标题页和“最小化功能区”的功能。在我的上下文菜单上:

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;
    }
}

答案 1 :(得分:1)

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; }
}

答案 2 :(得分:0)

最小化控件并且无法禁用的唯一方法是双击Tab标题,实际上三次点击或超过2次点击也可以最小化控件,这就是我的第一个想法失败的原因(我尝试过取消双击事件,但控件在第三次点击时最小化。

所以这个解决方案不是很好,但是当TabHeaderItemsControl上检测到超过两次点击时(这是保存标签的控件),它可以正常工作

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; }
}