Make a TextBlock Wrap Inside a Grid Column

I have the following XAML that shows a text block in a grid. The problem is that it just stretches, it even stretches more than the width of the window.

<Grid Background="Gray"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Label Grid.Row="1" Grid.Column="0" Padding="0" FontWeight="Bold" Margin="0,0,5,0">Description:</Label> <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Description}" TextWrapping="Wrap" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" /> </Grid> 
+4
source share
2 answers

You need to restrict the width second column to do the text wrapping -

 <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> 
+8
source

You need a grid divider

  <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="5" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Left side</TextBlock> <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" /> <TextBlock Grid.Column="2" FontSize="55" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap">Right side</TextBlock> </Grid> 
0
source

Source: https://habr.com/ru/post/1447800/


All Articles