RibbonControlsLibrary - 如何禁用最小化?

发布于 2024-12-04 21:04:27 字数 45 浏览 0 评论 0原文

如何从 RibbonControlsLibrary 禁用功能区控件的最小化?

How to disable minimizing of Ribbon control from RibbonControlsLibrary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

椒妓 2024-12-11 21:04:27

以下内容禁用了双击选项卡标题和上下文菜单上的“最小化功能区”:

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

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;
    }
}
生死何惧 2024-12-11 21:04:27
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; }
}
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; }
}
抚你发端 2024-12-11 21:04:27

最小化控件且无法禁用的唯一方法是双击选项卡标题,实际上三次单击或两次以上单击也会最小化控件,这就是我的第一个想法失败的原因(我试图取消双击事件,但控件在第三次单击时最小化)。

所以这个解决方案不太漂亮,但它工作正常,当在 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; }
}

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; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文