0

I have a ListBox which consists from items like this:

<ListBoxItem>
    <ListBoxItem.ContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=department}"></TextBlock>
        </DataTemplate>
    </ListBoxItem.ContentTemplate>
</ListBoxItem>

department is a string property :text="dept1\dept2\dept3\dept4\dept5\dept6" My problem is that when ListBox size is changing I want to change the TextBlock text in this way: text= dept1\dept2\...\dept6.

the length of (dept1\dept2\...\dept6) is equal or less than ListBoxItem actual size.

Nasreddine
  • 36,610
  • 17
  • 75
  • 94

1 Answers1

0

You need to set the TextTrimming property of your TextBlock to CharacterEllipsis like this -

<TextBlock Text="{Binding Path=department}" TextTrimming="CharacterEllipsis"/>

But this will show ellipsis at the end of the text if it gets greater than the size of the listboxitem. Something like this - "dept1\dept2\dept3\dept4\dept5..."

But however in case you want it in center, you might have to use ValueConverter to format the string. This might help - Ellipsis at start of string in WPF ListView

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185