Auto clip and append dots in WPF label

后端 未结 2 1059
旧时难觅i
旧时难觅i 2021-02-11 12:22

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

相关标签:
2条回答
  • 2021-02-11 12:57

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

    <Label>
         <TextBlock TextTrimming="CharacterEllipsis">Hello World</TextBlock>
    </Label>
    
    0 讨论(0)
  • 2021-02-11 13:00

    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.

    0 讨论(0)
提交回复
热议问题