简体   繁体   English

Gridsplitter没有显示

[英]Gridsplitter not showing

I am new to WPF. 我是WPF的新手。 I declared my Grid as so: 我声明我的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>

I basically want that 3rd column of width 5 to be the GridSplitter and to be resizeable for the left and right columns. 我基本上希望宽度为5的第3列是GridSplitter并且可以为左右列调整大小。 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. 我没有在列中看到GridSplitter Did I set it up right? 我把它设置得对吗? Thanks. 谢谢。

You have the GridSplitter centering in it's column, but it has no width defined. GridSplitter以其列为中心,但没有定义宽度。 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. 如果需要嵌套网格,则可能需要复制列定义。

I just ran this XAML and it works fine 我只是运行这个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>

Are you sure you want to put three rows inside 0th column? 您确定要在第0列中放置三行吗? 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. 但显然第一列没有三行我认为你错误地放在第0列。

I think what you want to do is first XAML I wrote 我想你想要做的就是我写的第一个XAML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM