首页 > 解决方案 > 工具栏中的 WPF 按钮位置

问题描述

我有一个垂直的 ToolBarTray 和一个带按钮的 ToolBar。虽然大多数按钮必须在上部,但我需要一个(退出按钮)在底部。但都是一个接一个的往下走。你能告诉我我应该怎么做才能把最后一个按钮从主组中分开吗?

谢谢!

标签: c#wpfxaml

解决方案


您可以使用两个 ToolBarTray 来实现它,如下所示:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ToolBarTray Grid.Row="0" Background="White" IsLocked="True" Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Left" >
            <ToolBar Band="1" BandIndex="1" >
                <Button Content="Cut"/>
                <Button Content="Copy"/>
                <Button Content="Paste"/>
            </ToolBar>
        </ToolBarTray>
        <ToolBarTray Grid.Row="1" Background="White" IsLocked="True" Orientation="Vertical" VerticalAlignment="Bottom" HorizontalAlignment="Left" >
            <ToolBar Band="1" BandIndex="1" >
                <Button Content="Exit" />
            </ToolBar>
        </ToolBarTray>
    </Grid>

然后它看起来像这样: 在此处输入图像描述


推荐阅读