How do I set the length of the TextBlock
so it fits in a ListViewItem
?
This is my xaml:
<ListView x:Name="flyList" BorderThickness="0" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border BorderThickness="0,0,0,1" BorderBrush="#FF7C7C7C">
<TextBlock Text="{Binding}" Tapped="TextBlock_Tapped" SelectionHighlightColor="#FF8F8F8F">
<ToolTipService.ToolTip>
<ToolTip Name="tip1" Content="Click to copy signal to clipboard."/>
</ToolTipService.ToolTip>
</TextBlock>
</Border>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
If the text is longer that the ListViewItem
width, the rest of the text is not visible obviously. Is there an easy way to make fit in it other than hardcode the text?
@CETINKAYA Ayta Ozden have a good way to solution but I think I should give you a code to explain.
The first thing is set ItemContainerStyle that use the code:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment"
Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
And replace the StackPanel to Grid.
And add TextWrapping="Wrap"
to TextBlock. @WPInfo Thx your way.
If you set the StackPanel that will make the min width and if you have not set the ItemContainerStyle that it's default is Left that means it will use the min width.