wpf 垂直和水平GridSplitter

zbq4xfa0  于 2023-05-13  发布在  其他
关注(0)|答案(3)|浏览(117)

我有一个网格,我试图把垂直和水平GridSplitters。这是我的主网格,我希望它尽可能地流畅。
在我的第二个定义中,我得到了“MissingGrid. Columnsetter for non-first child”
我已经找到了大量关于实现其中一个或另一个的文档。我没有发现任何迹象表明我可以两者兼得。但是,我们的行业是由想要推动功能的人组成的。
下面是我的XAML:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50*"></ColumnDefinition>
        <ColumnDefinition Width="5"></ColumnDefinition>
        <ColumnDefinition Width="50*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="50*"></RowDefinition>
        <RowDefinition Height="5"></RowDefinition>
        <RowDefinition Height="50*"></RowDefinition>
    </Grid.RowDefinitions>
    <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch"></GridSplitter>
    <GridSplitter  Grid.Row="1" Height="5" HorizontalAlignment="Stretch"></GridSplitter>
ijxebb2r

ijxebb2r1#

您需要设置网格分割器的Grid.Column,还需要

HorizontalAlignment="Stretch"  -> for horizontal splitter
VerticalAlignment="Stretch"  -> for Vertical splitter

所以你的代码看起来像

<GridSplitter Grid.Column="1" Width="5" Grid.RowSpan ="3" VerticalAlignment="Stretch"></GridSplitter>
<GridSplitter  Grid.Row="1" Height="5" Grid.ColumnSpan ="3" HorizontalAlignment="Stretch"></GridSplitter>
kx1ctssn

kx1ctssn2#

需要添加ResizeBehavior="PreviousAndNext",以允许对列和行进行适当调整。下面是我的样本。

<Grid ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50*"></ColumnDefinition>
        <ColumnDefinition Width="5"></ColumnDefinition>
        <ColumnDefinition Width="50*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="50*"></RowDefinition>
        <RowDefinition Height="5"></RowDefinition>
        <RowDefinition Height="50*"></RowDefinition>
    </Grid.RowDefinitions>
    <GridSplitter Grid.Column="1" Width="5" Grid.RowSpan ="3" 
                  VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext">
    </GridSplitter>
    <GridSplitter  Grid.Row="1" Height="5" Grid.ColumnSpan ="3" 
                   HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndNext">            
    </GridSplitter>
    <Button Grid.Row="0" Grid.Column="0" Content="1,1" FontSize="30"/>
    <Button Grid.Row="2" Grid.Column="0" Content="3,1" FontSize="30"/>
    <Button Grid.Row="0" Grid.Column="2" Content="1,3" FontSize="30"/>
    <Button Grid.Row="2" Grid.Column="2" Content="3,3" FontSize="30"/>
</Grid>
ktecyv1j

ktecyv1j3#

可以按如下方式设置方向:

<GridSplitter ResizeDirection=”Rows”/>

<GridSplitter ResizeDirection=”Columns”/>

但是,当您将“对齐”设置为“水平”或“垂直”时,默认的ResizeDirection=“自动”很可能会选择管件调整大小的方向。

相关问题