wpf 垂直和水平 GridSplitter

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34314466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:35:07  来源:igfitidea点击:

Vertical and horizontal GridSplitter

wpfgridsplitter

提问by CBlafer

I have a grid and I am trying to put both vertical and horizontal GridSplitters. It's my main grid and I would like it to be as fluid as possible.

我有一个网格,我试图同时放置垂直和水平 GridSplitter。这是我的主要网格,我希望它尽可能流畅。

On my second definition I get "Missing Grid.Column setter for non-first child"

在我的第二个定义中,我得到“Missing Grid.Column setter for non-first child”

I've found loads of documentation on implementing one or the other. I have found nothing suggesting that I can do both. But, our industry is made of people wanting to push functionality.

我发现了大量关于实现其中一个的文档。我没有发现任何迹象表明我可以做到这两点。但是,我们的行业是由想要推动功能的人组成的。

Here is my XAML:

这是我的 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>

回答by Muds

You need to set Grid.Column for grid splitters and also you need

您需要为网格拆分器设置 Grid.Column 并且您还需要

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

so your code looks like --

所以你的代码看起来像 -

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

回答by thewhiteambit

You can set the direction as follows:

您可以设置方向如下:

<GridSplitter ResizeDirection=”Rows”/>

or

或者

<GridSplitter ResizeDirection=”Columns”/>

However, when you set Alignment to either Horizontal or Vertical, the default ResizeDirection=”Auto” will most likely choose a fitting resize direction.

但是,当您将 Alignment 设置为 Horizo​​ntal 或 Vertical 时,默认的 ResizeDirection=”Auto” 很可能会选择合适的调整大小方向。

回答by namg_engr

ResizeHehavior="PreviousAndNext"needs to be added to allow proper adjustment of both columns and rows. See below for my sample.

ResizeHehavior="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>