문제

I'm trying to have text in a block truncate itself when the last line of the text would cause the bottom of the text box to slice it horizontally:

icon with text cut off

<DataTemplate x:Key="largeIconTemplate">
        <StackPanel Width="140" Height="180" >
            <Grid Width="120" Height="120" HorizontalAlignment="Center">
                <Image Source="{Binding IconName, Converter={x:Static converters:StringPathToBitmapImageConverter.Instance}}" Margin="6,6,6,9"/>
            </Grid>
            <TextBlock Text="{Binding Description}" TextWrapping="Wrap" TextAlignment="Center" Margin="0,0,0,1" />
        </StackPanel>
    </DataTemplate>

Setting TextTrimming options seems to make no difference. How to I get the text inside the TextBlock to truncate correctly? i.e. "fit as much of the line as possible with centering and wrapping, but truncate the text if it will be rendered as partially cutoff."

도움이 되었습니까?

해결책

Your DataTemplate is wrong. a StackPanel is not the appropiate container for that.

Use a DockPanel instead:

<DataTemplate x:Key="largeIconTemplate">
    <DockPanel Width="140" Height="180">
        <Image DockPanel.Dock="Top" Margin="6,6,6,9"
               Source="{Binding IconName, Converter={x:Static converters:StringPathToBitmapImageConverter.Instance}}"/>

        <TextBlock Text="{Binding Description}" 
                   TextTrimming="CharacterEllipsis" 
                   TextWrapping="Wrap" 
                   TextAlignment="Center" 
                   Margin="0,0,0,1" />
    </DockPanel>
</DataTemplate>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top