Auto clip and append dots in WPF label

三世轮回 提交于 2019-12-05 08:22:35

问题


How can I auto clip text and append dots on a label if the current text doesn't fits to its width in WPF?


回答1:


Put a TextBlock inside your label and set TextTrimming to CharacterEllipsis or WordEllipsis

<Label>
     <TextBlock TextTrimming="CharacterEllipsis">Hello World</TextBlock>
</Label>



回答2:


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.



来源:https://stackoverflow.com/questions/2996155/auto-clip-and-append-dots-in-wpf-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!