WPF 工具栏:如何删除夹点和溢出 [英] WPF ToolBar: how to remove grip and overflow

查看:36
本文介绍了WPF 工具栏:如何删除夹点和溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在嵌套的 WPF ToolBarPanel-ToolBar-Menu 中,我们希望摆脱左侧的手柄和右侧的溢出区域.它们都显示为灰色,但我们希望它们根本不显示.

In a nested WPF ToolBarPanel-ToolBar-Menu we want to get rid of the grip handle to the left and the overflow area to the right. they are both grayed out, but we'd like them to not be displayed at all.

关于如何实现这一目标的任何想法?

any ideas on how to accomplish that?

以防万一我的术语不完全正确,如果您查看下面链接的图 3 中的图像,在三个工具栏的最低处,下拉菜单左侧和右侧有一个手柄最右边的按钮是溢出.

just in case my terms aren't entirely correct, if you look at the image in Figure 3 of the link below, on the lowest of the three toolbars there's the grip to the left of the dropdown and to the right of the right-most button there's the overflow.

工具栏图片

推荐答案

可以通过设置 ToolBar 上的附加属性 ToolBarTray.IsLocked="True" 来移除手柄.

The grip can be removed by setting the attached property ToolBarTray.IsLocked="True" on the ToolBar.

要删除溢出切换按钮,您必须将其删除在自定义 ControlTemplate 中,如 Sixlettervariables 建议的那样,如果您有混合或可以下载混合 3 预览并不太困难.

To remove the Overflow ToggleButton, you will have to remove it in a custom ControlTemplate as sixlettervariables suggests, which if you have blend or can download the Blend 3 Preview is not overly difficult.

您也可以在工具栏的加载事件中隐藏按钮,无论您采用哪种方式,您还应该在工具栏的菜单上设置附加属性 ToolBar.OverflowMode="Never",以免物品意外溢出到无法到达的区域.

You could also just hide the button in the loaded event of the ToolBar, though whichever route you take, you should also set the attached property ToolBar.OverflowMode="Never" on the ToolBar's menu, so that items cannot accidentally overflow into an unreachable area.

<ToolBarPanel DockPanel.Dock="Top">
    <ToolBar ToolBarTray.IsLocked="True" Loaded="ToolBar_Loaded">
        <Menu ToolBar.OverflowMode="Never">
            <MenuItem Header="File" />
            <MenuItem Header="New" />
        </Menu>
    </ToolBar>
</ToolBarPanel>

并将溢出切换按钮设置为折叠:

And set the Overflow ToggleButton to collapsed:

private void ToolBar_Loaded(object sender, RoutedEventArgs e)
{
    ToolBar toolBar = sender as ToolBar;
    var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
    if (overflowGrid != null)
    {
        overflowGrid.Visibility = Visibility.Collapsed;
    }
    var mainPanelBorder = toolBar.Template.FindName("MainPanelBorder", toolBar) as FrameworkElement;
    if (mainPanelBorder != null)
    {
        mainPanelBorder.Margin = new Thickness();
    }
}

这篇关于WPF 工具栏:如何删除夹点和溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆