如何创建这个 wpf 工具栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15001145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:39:41  来源:igfitidea点击:

How create this wpf toolbar

c#wpfxamltoolbar

提问by Walter Fabio Simoni

I would like to create a toolbar like this on wpf.

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

enter image description here

在此处输入图片说明

What i need to use in order to create the area with the button circled in red ? Is it possible with the microsoft toolbar ?

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

For the moment i tried this :

目前我试过这个:

enter image description here

在此处输入图片说明

Here is my xaml code :

这是我的 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) First, i would like to know how centered the button, i add the verticalAlignment="Center", but nothing is center. Have you an idea please?

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

2) Secondly, how remove or hide the little rectangle white on the right please ?

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

3) Then, anyone know how it's possible to recreate the area circled on red please ?

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

Thanks a lot :)

非常感谢 :)

Best regards

此致

回答by mike01010

Your tool bar looks centered. do you mean you want the toolbar to be where the caption/title is or do you want to hide the caption title? for the latter you can try WindowStyle="None" in your window.

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

As for for the 'little rectangle" try getting and setting OverflowGrid visibility property of the toolbar.

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

you probably also need to wrap the elments in aborder and use the corner radius to achieve the rounded corners. here's an example:

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

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