How can I auto clip text and append dots on a label if the current text doesn't fits to its width in WPF?
Asked
Active
Viewed 2.6k times
2 Answers
114
Put a TextBlock inside your label and set TextTrimming to CharacterEllipsis or WordEllipsis
<Label>
<TextBlock TextTrimming="CharacterEllipsis">Hello World</TextBlock>
</Label>

John Cummings
- 1,949
- 3
- 22
- 38

Ray
- 45,695
- 27
- 126
- 169
-
1Hell no! This is what you hope for, but you know they couldn't have made it that easy! Really cool feature! – bas Sep 11 '15 at 21:47
-
For some vague reason (is anything not vague in wpf?) this is working in my designer, but not at runtime – Edwin Mar 04 '17 at 22:17
-
Nevermind, I needed to assign text to the textblock and not use label.Content anymore in my code. – Edwin Mar 04 '17 at 22:34
1
It's also possible to use AccessText within the Label like this:
<StackPanel Orientation="Horizontal">
<Label VerticalAlignment="Center" Width="50"
Target="{Binding ElementName=txtName}">
<AccessText Text="_First Name" TextTrimming="CharacterEllipsis" />
</Label>
<TextBox Name="txtName" VerticalAlignment="Center" Width="120"/>
With this solution the access key for a control (e.g. Alt+F) still works.

Steven G.
- 31
- 2