网格分割器未显示

发布于 2024-11-30 15:41:07 字数 972 浏览 3 评论 0原文

我是 WPF 新手。我这样声明我的 Grid:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"></ColumnDefinition>
    <ColumnDefinition Width="5"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
     <Grid.RowDefinitions>
         <RowDefinition Height="*"></RowDefinition>
         <RowDefinition Height="*"></RowDefinition>
         <RowDefinition Height="*"></RowDefinition>
     </Grid.RowDefinitions>
</Grid>

我基本上希望宽度为 5 的第三列成为 GridSplitter,并且可以调整左右列的大小。所以我有分割器的代码:

<GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" Height="Auto"
              VerticalAlignment="Stretch" HorizontalAlignment="Center"
              Margin="0" Background="Black"/>

我在列中没有看到 GridSplitter 。我设置对了吗?谢谢。

I am new to WPF. I declared my Grid as so:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"></ColumnDefinition>
    <ColumnDefinition Width="5"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
     <Grid.RowDefinitions>
         <RowDefinition Height="*"></RowDefinition>
         <RowDefinition Height="*"></RowDefinition>
         <RowDefinition Height="*"></RowDefinition>
     </Grid.RowDefinitions>
</Grid>

I basically want that 3rd column of width 5 to be the GridSplitter and to be resizeable for the left and right columns. So I have this code for the splitter:

<GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" Height="Auto"
              VerticalAlignment="Stretch" HorizontalAlignment="Center"
              Margin="0" Background="Black"/>

I do not see the GridSplitter in the column. Did I set it up right? Thanks.

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

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

发布评论

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

评论(2

尤怨 2024-12-07 15:41:07

您将 GridSplitter 置于其列的中心,但没有定义宽度。所以你实际上是以零宽度将其居中。看起来您也有两个网格,而您需要一个。

似乎您想要这样的东西:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>

    <GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" Height="Auto"
         Width="5" VerticalAlignment="Stretch" Margin="0" Background="Black"/>

</Grid>

如果您需要嵌套网格,那么您可能需要复制列定义。

You have the GridSplitter centering in it's column, but it has no width defined. So you are effectively centering it with a width of zero. It also looks like you have two Grids, where you'd need one.

Seems like you want something like this:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>

    <GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" Height="Auto"
         Width="5" VerticalAlignment="Stretch" Margin="0" Background="Black"/>

</Grid>

If you need the nested Grid, then you may need to duplicate the Column definitions.

拥抱影子 2024-12-07 15:41:07

我刚刚运行了这个 XAML,它工作正常

<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="5"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>


    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>

    <TextBox Grid.Column="0" MinWidth="100" />
    <GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" HorizontalAlignment="Stretch" />

    <TextBox Grid.Column="2" MinWidth="100" />
</Grid>

您确定要将三行放入第 0 列吗?因为这没有多大意义

你正在这样做,

<GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Center"
                            Margin="0" Background="Black"/>

但显然第一列没有三行,我认为你错误地将其放置在第 0 列中。

我认为你想要做的是我编写的第一个 XAML

I just ran this XAML and it works fine

<Grid >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"></ColumnDefinition>
        <ColumnDefinition Width="5"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>


    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>

    <TextBox Grid.Column="0" MinWidth="100" />
    <GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" HorizontalAlignment="Stretch" />

    <TextBox Grid.Column="2" MinWidth="100" />
</Grid>

Are you sure you want to put three rows inside 0th column? because it doesn't make much sense

And you are doing this

<GridSplitter Grid.Column="1" Grid.RowSpan="3" ResizeDirection="Columns" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Center"
                            Margin="0" Background="Black"/>

But apparently first column don't have three rows which I think you have mistakenly placed in column 0.

I think what you want to do is first XAML I wrote

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