No need to do it yourself, TextBlock
can already do this for you:
<TextBlock TextTrimming="CharacterEllipsis"/>
It seems your text is in a list of some sort you need to set this on the TextBlock
in a DataTemplate
for each item in the list, e.g.:
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock TextTrimming="CharacterEllipsis"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Of course if your TextBlock
is in a pane that grows as it needs then there is nothing to trim - you can set a fixed size on your TextBlock
, or your ListView
and disable horizontal scrolling.