WPF Grid Column MaxWidth Not Applicable

This problem occurs due to the inability to migrate my TextBlock. Basically, as an attempt at the last attempt, I set MaxWidth on my container grid columns. I was surprised to find that my shortcut and text box still do everything they want (bad kids, BAD) and are not limited to my grid column MaxWidth = "200".

What I'm really trying to do is let my TextBlock fill the available width and wrap if necessary. As long as all attempts to HorizontalAlignment = "Stretch" on all known parents in the universe fail, nothing works except setting explicit MaxWidth = "400" or any other number in the TextBlock. This is not good, because I need the TextBlock to fill the available width, not limited to some fixed number. Thanks!

<ItemsControl> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition MaxWidth="200" SharedSizeGroup="A" /> <ColumnDefinition MaxWidth="200" SharedSizeGroup="B" /> </Grid.ColumnDefinitions> <Label VerticalAlignment="Top" Margin="0 5 0 0" Grid.Column="0" Style="{StaticResource LabelStyle}" Width="Auto" Content="{Binding Value.Summary}" /> <TextBlock Grid.Column="1" Margin="5,8,5,8" FontWeight="Normal" Background="AliceBlue" Foreground="Black" Text="{Binding Value.Description}" HorizontalAlignment="Stretch" TextWrapping="Wrap" Height="Auto" /> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 
+6
layout wpf grid textwrapping
source share
2 answers

I tried to replicate your problem by inserting all the Grid elements into Kaxaml, but everything wraps around as you expected. (I inserted regular lines where you made bindings and removed the Label style).

Maybe the problem is above the tree.

I would suggest inserting chunks in Kaxaml or similarly to a test and see which parent violates your user interface.

+2
source share

I provided an answer to this question, only he used ListView instead of ItemControl, but the problem is probably the same. ScrollViewer probably surrounds your ItemPresenter and you need to edit a copy of the ItemsControl template.

WPF ListView TextBlock TextWrapping

+1
source share

All Articles