質問

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