Есть ли в WPF Rowspan = «все»?
-
10-10-2019 - |
Вопрос
Я создаю GridSplitter
В 3 рядах, которые у меня есть в моей сети так:
<GridSplitter Grid.Row="0" Grid.Column="1" Background="Yellow"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Width="Auto" Height="Auto" ResizeDirection="Columns"
Grid.RowSpan="3" ...
Тем не менее, вполне возможно, что я мог бы добавить еще один ряд в свою сетку на более позднем этапе, и я не хочу возвращаться и обновлять все свои Rowspans.
Мое первое предположение было Grid.RowSpan="*"
, но это не компилируется.
Решение
Вы можете привязать к 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();
}
}
}
Другие советы
Простое решение:
<!-- RowSpan == Int32.MaxValue -->
<GridSplitter Grid.Row="0"
Grid.Column="1"
Grid.RowSpan="2147483647" />
А Grid
Управление не дает ничего подобного из коробки. Возможно, что вы можете реализовать MarkupExtension
Или какое -то другое хитрость, чтобы включить это.
Не связан с StackOverflow