Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextTrimming from left

Tags:

Is there a way to specify text trimming on a TextBlock to be from the left side?

I've manage to accomplish two out of three scenarios (the third being the one I need):

  1. Regular trimming

    <TextBlock 
        VerticalAlignment="Center" 
        Width="80" 
        TextTrimming="WordEllipsis"
        Text="A very long text that requires trimming" />
    
    // Result: "A very long te..."
    
  2. Left trimming

    <TextBlock 
        VerticalAlignment="Center" 
        Width="80" 
        FlowDirection="RightToLeft"
        TextTrimming="WordEllipsis"
        Text="A very long text that requires trimming." />
    
    // Result: "...A very long te"
    
  3. Left trimming where the end of the text is seen

    // Desired result: "...uires trimming"
    

Does anyone know if this is possible? Thanks.

like image 533
Boris Avatar asked Jan 19 '12 14:01

Boris


1 Answers

If you don't care about the ellipses, but just want to see the end of the text instead of the beginning when it gets cut-off, you can wrap the TextBlock inside another container, and set its HorizontalAlignment to Right. This will cut it off just like you want, but without the elipse.

<Grid>
    <TextBlock Text="Really long text to cutoff." HorizontalAlignment="Right"/>
</Grid>
like image 196
Jeffrey Harmon Avatar answered Nov 14 '22 14:11

Jeffrey Harmon