c# - 如何创建这个 wpf 工具栏

标签 c# wpf xaml toolbar

我想在 wpf 上创建一个这样的工具栏。

enter image description here

我需要使用什么来创建带有红色圆圈按钮的区域? 可以使用 Microsoft 工具栏吗?

目前我试过这个:

enter image description here

这是我的 xaml 代码:

    <ToolBarTray Background="#008ede" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="33" >
        <ToolBar ToolBarTray.IsLocked="True" Background="#008ede" HorizontalAlignment="Stretch"  VerticalAlignment="Center"  VerticalContentAlignment="Center">
            <Button Name="tbrClear" ToolTip="Clear" VerticalAlignment="Center">
                <Image Source="_XWPF_TBR_PREMIER.PNG_IMAGES.png" Name="Image1"></Image>
            </Button>
            <Button Name="tbrClear_" ToolTip="Clear" VerticalAlignment="Center" VerticalContentAlignment="Center">
                <Image Source="_XWPF_TBR_PRECED.PNG_IMAGES.png" Name="Image2"></Image>
            </Button>
        </ToolBar>    
    </ToolBarTray>

1) 首先,我想知道按钮是如何居中的,我添加了 verticalAlignment="Center",但没有任何东西是居中的。请问你有什么想法吗?

2)其次,请问如何删除或隐藏右边的白色小矩形?

3) 那么,有人知道如何重新创建红色圈出的区域吗?

非常感谢:)

最好的问候

最佳答案

您的工具栏看起来居中。你是说你想让工具栏位于标题/标题所在的位置还是你想隐藏标题?对于后者,您可以在窗口中尝试 WindowStyle="None"。

至于“小矩形”,请尝试获取和设置工具栏的 OverflowGrid 可见性属性。

您可能还需要将元素包裹在边框中并使用圆角半径来实现圆角。这是一个例子:

    <DockPanel  Height="40" VerticalAlignment="Top">
        <Border BorderBrush="LightBlue" BorderThickness="1" CornerRadius="8" Margin="1" Background="#008ede">
                <ToolBarTray Background="#008ede" HorizontalAlignment="Left" VerticalAlignment="Center"  >
                    <ToolBar ToolBarTray.IsLocked="True" Background="Transparent"  HorizontalAlignment="Stretch"  VerticalAlignment="Center"  VerticalContentAlignment="Center">
                        <Button Name="tbrClear" ToolTip="Clear" VerticalAlignment="Center">
                            <Image Source="_XWPF_TBR_PREMIER.PNG_IMAGES.png" Name="Image1"></Image>
                        </Button>
                        <Button Name="tbrClear_" ToolTip="Clear" VerticalAlignment="Center" VerticalContentAlignment="Center">
                            <Image Source="_XWPF_TBR_PRECED.PNG_IMAGES.png" Name="Image2"></Image>
                        </Button>
                    </ToolBar>
                </ToolBarTray>
        </Border>
    </DockPanel>

关于c# - 如何创建这个 wpf 工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15001145/

相关文章:

c# - ReactiveCommand 的前后 Action

c# - 允许用户通过拖动调整 WPF TreeView 节点的大小

wpf - 动态更改 WPF ComboBox 的 ItemsSource

c# - 将多个 TreeView 的属性绑定(bind)到同一个 ViewModel

c# - 检测 Windows 8.1 商店应用程序是否处于 SplittView 或 FullView

wpf - 您如何管理庞大且几乎无法维护的 XAML 文件?

c# - 通过 id linq to xml C# 选择一个对象

c# - 无法远程调试 .Net 应用程序 "no symbols have been loaded for this document."

c# - 在抛出的 clr 异常上创建核心转储

c# - 通过运行时加载 XAML XML?