C# WPF如何使工具栏在工具栏容器中右对齐

3

我有三个 WPF 工具栏在一个工具栏容器中,我想让其中两个在左边,而另一个则浮动在右边。

<ToolBarTray DockPanel.Dock="Top">
        <ToolBar>
            <ComboBox/>
        </ToolBar>
        <ToolBar>
            <Button/>
            <Button/>
            <Button/>
        </ToolBar>
        <ToolBar HorizontalAlignment="Right">
            <Button/>
            <Button/>
            <Button/>
        </ToolBar>
</ToolBarTray>

我曾经试图以编程的方式设置最右边工具栏的边距,但感觉很不正规。在运行时,可以在托盘中移动工具栏,所以我觉得我可能忽略了一些明显的东西。
也许我应该使用不同的控件?
1个回答

0

希望我有所帮助

代码来自Mark Cidade的回答(https://dev59.com/3nE95IYBdhLWcg3wrP-w#21293250):

<ToolBar VerticalAlignment="Top">
    <ToolBar.Resources>
        <Style TargetType="{x:Type ToolBarPanel}">
            <Setter Property="Orientation" Value="Vertical"/>
        </Style>
    </ToolBar.Resources>

    <DockPanel>
        <ToolBarPanel Orientation="Horizontal" >
            <Button>A</Button>
            <Button>B</Button>
        </ToolBarPanel>
        <Button DockPanel.Dock="Right" HorizontalAlignment="Right">C</Button>
    </DockPanel>
</ToolBar>

我认为我看到了这个答案,我的问题是我实际上正在使用一些从ToolBar派生的自定义用户控件,我想把它们都放在一个栏(托盘)中并进行布局。 - tomcheney

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接