Its simple by setting the "TextWrapping" property to "Wrap".
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
<TextBlock Text="{Binding}" TextWrapping="Wrap"/>
<StackPanel HorizontalAlignment="Stretch"> <TextBlock Text="Sample" /> <ListBox Name="MyListBox"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> <TextBlock Text="Hello" /> </Grid> <Grid Grid.Column="1"> <TextBlock Text="Hello" /> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel>
<StackPanel HorizontalAlignment="Stretch"> <TextBlock Text="Sample" /> <ListBox Name="MyListBox"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> </Style> </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="8*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> <TextBlock Text="Hello" /> </Grid> <Grid Grid.Column="1"> <TextBlock Text="Hello" /> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel>
<Style TargetType="ListBoxItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> </Style> </ListBox.ItemContainerStyle>This ensures that the ListBoxItem contents stretches to 100%.
<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="8*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <Grid Grid.Column="0">We want the first column to consume 80% of the width of the Grid and second column to occupy 20%.
<configuration ...> <system.web> <compilation ... batch="false"/>