Search code examples
xamlwindows-phone-8

Show '...' when text is longer that the area in textblock


Some days back i saw an example of what i need now but couldn't remind what was the way.

I want to show the text description in TextBlock and if the text is more that the size of text block, show the ...


Solution

  • Use below code to achieve this,

     <TextBlock Text="{StaticResource someText}"
                    TextWrapping="Wrap" TextTrimming="CharacterEllipsis"
                    Margin="10"/>
    

    And possible values of TextTrimming are as below,

    • None – no ellipsis, text is clipped (the default)
    • CharacterEllipsis – display as many characters as possible, followed by an ellipsis
    • WordEllipsis – display as many words as possible, followed by an ellipsis