32

GridSplitterグリッドにある3つの行に次のように作成します。

<GridSplitter Grid.Row="0" Grid.Column="1" Background="Yellow"
              HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
              Width="Auto" Height="Auto" ResizeDirection="Columns"
              Grid.RowSpan="3" ...

ただし、後の段階でグリッドに別の行を追加する可能性があるため、戻ってすべての行スパンを更新したくはありません。

私の最初の推測はでしたがGrid.RowSpan="*"、それはコンパイルされません。

4

3 に答える 3

41

簡単な解決策:

<!-- RowSpan == Int32.MaxValue -->
<GridSplitter Grid.Row="0"
              Grid.Column="1"
              Grid.RowSpan="2147483647" />
于 2011-01-11T23:11:42.817 に答える
18

RowDefinitions.Countにバインドできますが、行を手動で追加する場合はバインドを更新する必要があります。

編集:実際には半手動でのみ
Xaml:

<StackPanel Orientation="Vertical">
    <Grid Name="GridThing">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>   
            <ColumnDefinition/>         
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
            <RowDefinition />   
            </Grid.RowDefinitions>
            <Grid.Children>
                <Button Content="TopRight" Grid.Row="0" Grid.Column="1"/>
                <Button Content="LowerRight" Grid.Row="1" Grid.Column="1"/>
            <Button Content="Span Rows" Name="BSpan" Grid.RowSpan="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=RowDefinitions.Count, Mode=OneWay}"/>
        </Grid.Children>
        </Grid>
    <Button Click="Button_Click" Content="Add Row" />
</StackPanel>

コード:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        GridThing.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(20) });
        foreach (FrameworkElement child in GridThing.Children)
        {
            BindingExpression exp = child.GetBindingExpression(Grid.RowSpanProperty);
            if (exp != null)
            {
                exp.UpdateTarget();
            }
        }
    }
于 2011-01-11T22:51:56.803 に答える
1

Gridコントロールは、箱から出してこのようなものを何も提供しません。MarkupExtensionこれを可能にするために、または他のトリックを実装できると考えられます。

于 2011-01-11T22:48:49.980 に答える