Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a RowSpan="All" in WPF?

I create a GridSplitter across the 3 rows that I have in my grid like this:

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

However, it's conceivable that I might add another row to my grid at a later stage, and I don't really want to go back and update all of my rowspans.

My first guess was Grid.RowSpan="*", but that doesn't compile.

like image 666
Chris Spicer Avatar asked Jan 11 '11 22:01

Chris Spicer


People also ask

What is grid RowSpan in WPF?

You can span across multiple rows and columns using the Grid. RowSpan and Grid. ColumnSpan attached properties. The default value for both these properties is 1. The Grid will attempt to assign as many row spans or column spans as it can up to the amount specified by the Grid.

What is grid splitter in WPF?

A GridSplitter is a divider that divides a Grid into two sections. A GridSplitter allows us to resize rows or columns in a Grid by dragging the GridSplitter Bar. An example of a GridSplitter is the Windows Explorer.


2 Answers

A simple solution:

<!-- RowSpan == Int32.MaxValue --> <GridSplitter Grid.Row="0"               Grid.Column="1"               Grid.RowSpan="2147483647" /> 
like image 100
user7116 Avatar answered Sep 21 '22 14:09

user7116


You can bind to the RowDefinitions.Count but would need to update the binding when adding rows manually.

Edit: Only semi-manually in fact
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> 

Code:

    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();             }         }     } 
like image 25
H.B. Avatar answered Sep 18 '22 14:09

H.B.