Ellipsis at start of string in WPF ListView

前端 未结 6 1897
野的像风
野的像风 2020-12-06 06:05

I have a WPF ListView (GridView) and the cell template contains a TextBlock. If I add: TextTrimming=\"CharacterEllipsis\" TextWr

6条回答
  •  心在旅途
    2020-12-06 06:59

    I implemented (copied) the above TextBlockTrimmer code and it worked great for loading but the TextBlock.Text would not update afterwards, if bound to a View Model property that changed. What I found that worked was to

    1. Define a DependencyProperty called TextBlockText in TextBlockTrimmer, similar to the EllipsisPosition property above, including an OnTextBlockTextChanged() method.
    2. In the OnTextBlockTextChanged() method, set _originalText to newValue before calling TrimText().
    3. Bind the TextBlockText property to the View Model property (called SomeText in the XAML below)
    4. Bind the TextBlock.Text property to the TextBlockTrimmer.TextBlockText property in the XAML:

      
      
      

    It also worked if I bound both TextBlockTrimmer.TextBlockText and TextBlock.Text to SomeText (but doing so bugs me).

提交回复
热议问题