Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 共享网格中的列或行_Wpf_Grid - Fatal编程技术网

Wpf 共享网格中的列或行

Wpf 共享网格中的列或行,wpf,grid,Wpf,Grid,我正在尝试使用网格创建一个不对称布局,其中我有2行、2列和一个额外的共享列,如下所示: <Grid Background="Black"> <Grid.RowDefinitions> <RowDefinition Height="200" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Grid.ColumnDe

我正在尝试使用网格创建一个不对称布局,其中我有2行、2列和一个额外的共享列,如下所示:

<Grid Background="Black">
    <Grid.RowDefinitions>
        <RowDefinition Height="200" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Rectangle
        Grid.Row="0"
        Grid.Column="0"
        Width="200"
        Height="200"
        Fill="Red" />
    <Rectangle
        Grid.Row="0"
        Grid.Column="1"
        Grid.ColumnSpan="2"
        Width="250"
        Height="200"
        Fill="Blue" />
    <Rectangle
        Grid.Row="1"
        Grid.Column="0"
        Grid.ColumnSpan="2"
        Width="250"
        Height="200"
        Fill="Yellow" />
    <Rectangle
        Grid.Row="1"
        Grid.Column="2"
        Width="200"
        Height="200"
        Fill="Green" />
</Grid>
但不管我如何设置,第二列总是会折叠,除非我在本例中明确设置了固定宽度50px。为什么会这样

第二列的大小不应该调整为每个矩形的剩余部分吗?

使用转换器,我将第一列的内容放在容器中,并将共享列的宽度绑定到该容器的实际宽度减去第一列宽度,从而手动计算共享列的大小

e、 g


您是否尝试将列0和列2的宽度设置为自动,将列1的宽度设置为*?但这意味着如果我不设置最后一个矩形的大小,它将崩溃。对不起,我解释得不够。我的目标基本上是有4个不同的视图,其中3个折叠,最后一个扩展。因此,使用*填充窗口。目前,我确实使用转换器来计算共享列大小,但我希望使用一种不涉及转换器的方法。
<Grid Background="Black">
    <Grid.RowDefinitions>
        <RowDefinition Height="200" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200" />
        <ColumnDefinition Width="{Binding ElementName=Rect3, Path=ActualWidth, Converter={StaticResource SharedColumnConverter}, ConverterParameter=200}" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Rectangle
        Grid.Row="0"
        Grid.Column="0"
        Width="200"
        Height="200"
        Fill="Red" />
    <Rectangle
        Grid.Row="0"
        Grid.Column="1"
        Grid.ColumnSpan="2"
        Width="250"
        Height="200"
        Fill="Blue" />
    <Rectangle
        Name="Rect3"
        Grid.Row="1"
        Grid.Column="0"
        Grid.ColumnSpan="2"
        Width="250"
        Height="200"
        Fill="Yellow" />
    <Rectangle
        Grid.Row="1"
        Grid.Column="2"
        Width="200"
        Height="200"
        Fill="Green" />
</Grid>