Reputation: 69
I have a row on a xaml pages with three group boxes in it.
Here is the code:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<GroupBox Grid.Column="0" Grid.Row="0">
<ScrollViewer>
<TextBlock TextWrapping="WrapWithOverflow" Text="one"/>
</ScrollViewer>
</GroupBox>
<GroupBox Grid.Column="1" Grid.Row="0">
<ScrollViewer>
<TextBlock TextWrapping="WrapWithOverflow" Text="two"/>
</ScrollViewer>
</GroupBox>
<GroupBox Grid.Column="2" Grid.Row="0">
<ScrollViewer>
<TextBlock TextWrapping="WrapWithOverflow" Text="three"/>
</ScrollViewer>
</GroupBox>
</Grid>
The three group boxes have long text that wraps and had a scroll bar. The issue is that not all of these groupboxes will be displayed at the same time. Sometimes it will be just one, two or all.
When put the columns to auto the first one just takes over, and the same happens when I use a dockpannel or a stackpannel.
My question is how can I have the width change to take up the full width of the page if the second or third groupboxes have collapsed visibility. Thanks!
Upvotes: 0
Views: 478
Reputation: 35681
you can use UniformGrid with aa single row. it will adjust column width according to number of children
<UniformGrid Rows="1">
<GroupBox>
<ScrollViewer>
<TextBlock TextWrapping="WrapWithOverflow" Text="one"/>
</ScrollViewer>
</GroupBox>
<GroupBox>
<ScrollViewer>
<TextBlock TextWrapping="WrapWithOverflow" Text="two"/>
</ScrollViewer>
</GroupBox>
<GroupBox>
<ScrollViewer>
<TextBlock TextWrapping="WrapWithOverflow" Text="three"/>
</ScrollViewer>
</GroupBox>
</UniformGrid>
Upvotes: 4