WPF 网格按钮之间的分隔符

发布于 2024-08-13 21:41:32 字数 181 浏览 1 评论 0原文

我有一个带有 4 个按钮的网格...1 行,4 列。我正在寻找一种方法来直观地将左侧的两个按钮与右侧的两个按钮分组。我一直在寻找一种使用分隔符来完成此操作的方法,但它似乎与 Grid 配合不佳,更喜欢 StackPanel。

这是正确的控制吗?
如果是这样,如何使该东西分隔列(在本例中用按钮填充)?

谢谢。

I have a grid with 4 buttons...1 row, 4 columns. I am looking for a way to visually group the two buttons on the left from the two on the right. I was looking for a way to do this with a separator but it doesnt seem to be playing nice with Grid, preferring StackPanel.

Is this the right control?
If so, how does one make the thing separate the columns (populated with buttons in this case)?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

提笔落墨 2024-08-20 21:41:32

如果其他人偶然发现这个最简单的解决方案:

<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />

In case anyone else stumbles across this, easiest solution:

<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
甜中书 2024-08-20 21:41:32

您是否尝试过GridSplitter

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Height="*" />
        <ColumnDefinition Height="Auto" />
        <ColumnDefinition Height="100" />
        <ColumnDefinition Height="100" />
    </Grid.ColumnDefinitions>
    <Button/>
    <Button/>
    <GridSplitter ResizeDirection="Columns" Grid.Column="2" Height="Auto" Width="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
    <Button/>
</Grid>

Have you tried a GridSplitter?

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Height="*" />
        <ColumnDefinition Height="Auto" />
        <ColumnDefinition Height="100" />
        <ColumnDefinition Height="100" />
    </Grid.ColumnDefinitions>
    <Button/>
    <Button/>
    <GridSplitter ResizeDirection="Columns" Grid.Column="2" Height="Auto" Width="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
    <Button/>
</Grid>
苍景流年 2024-08-20 21:41:32

我通常使用简单的选择在按钮之间添加一个具有固定宽度的列
您实际上可以使用不同的背景颜色或插入图像

I usually use the simple choice to add a column with a fixed width between the buttons
You can actually use a different background color or insert an image

白色秋天 2024-08-20 21:41:32

如果样式正确,则可以使用分隔符。默认情况下,它会创建一条水平线。您必须应用不同的样式才能使其垂直。
请参阅这篇文章,了解如何将其样式设置为 WPF 网格中的垂直线:

CodeProject 讨论

该讨论还提到 StatusBar 对 Separator 元素应用一些样式,只要您不将它们包装在 StatusBarItems 中即可。也许 StackPanel 也做了类似的事情。

You can use Separator if you style it correctly. By default it creates a horizontal line. You have to apply different styling to make it vertical.
See this post for how to style it as a vertical line in a WPF Grid:

CodeProject discussion

The discussion also mentions that StatusBar applies some styling to Separator elements, as long as you don't wrap them in StatusBarItems. Perhaps StackPanel does something similar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文