WPF ListView TextBlock TextWrapping

I am creating a ListView that should have five columns - the first should have text that can be of any length and should be wrapped whenever the window is resized (in addition to changing the height of the line so that the wrapped text is visible), and the remaining four columns - the static width is 45. I was looking for a watch on this, and every solution that I come across either requires a static width or does not work.

Solutions tried:

Auto column widths, 1 *, 2 *, etc. (parameters are ignored) DockPanel (settings are ignored) WrapPanel (ignored) Set the width in the RelativeSource of the parent for ActualWidth (ignored)

Any ideas? It seems that a significant part of the people had the same problem, but I would prefer that I didn't have to go the static width path for this column. Moreover, the content is simply turned off when I do this (even with height = "Auto" for the line). The width of the whole window can be as high as 1024, but it can also be 1600+, so I want a dynamic size. That way, smaller screens will contain a content wrapper, and larger screens will only show one line as the content fits.

Here is the XAML:

<ListView.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="45" /> <ColumnDefinition Width="45" /> <ColumnDefinition Width="45" /> <ColumnDefinition Width="45" /> </Grid.ColumnDefinitions> <!-- This is the TextBlock that needs to wrap its content (and change the height of the row (so the full content is still visible) to whatever the available space is, but should not make overall ListView wider than the parent width. --> <TextBlock Text="{Binding Content}" Padding="20,6,6,6" /> <!-- These four blocks will have other content eventually, but only need to be 45 wide --> <TextBlock Text="X" Grid.Column="1" HorizontalAlignment="Center" /> <TextBlock Text="X" Grid.Column="2" HorizontalAlignment="Center" /> <TextBlock Text="X" Grid.Column="3" HorizontalAlignment="Center" /> <TextBlock Text="X" Grid.Column="4" HorizontalAlignment="Center" /> </Grid> </DataTemplate> </ListView.ItemTemplate> 
+1
listview wpf grid textwrapping
source share
2 answers

Not so simple ... but it can be done.

I wrote you a solution. In short, use Expression Blend to create a copy of the ListView template and remove the ScrollViewer surrounding the ItemPresenter.

Here is a more detailed explanation:

How to make a TextBlock in the left column of a grid in a ListView template expand or contract using text wrapping?

+1
source share

I would add TextWrapping = "Wrap" to the first TextBlock element.

-one
source share

All Articles