Question

I have a listview with an itemtemplate:

<ListView x:Name="messages" HorizontalAlignment="Left" 
    Background="{x:Null}" BorderBrush="{x:Null}" Foreground="Black">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextBlock Style="{DynamicResource h3}" Text="{Binding}"
                Margin="10" MaxWidth="850"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

This listview is in a vertical stackpanel. So its width is the same as the stackpanel's width.

The listview must show messages that could be very long. I'm trying to make sure that when a message is too long for the available width, the textblock gets extra height and the text gets displayed on 2 lines.

I can google a lot of ways to have this achieved with a fixed height, but since I don't know in advance if I'll need more than 1 line, I'd like to make sure it happens automaticly. I don't want every item to have the height of 2 lines, only when it's needed.

How can I achieve this?

Was it helpful?

Solution

Have you tried the TextWrapping property? It seems that it would do what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top