WPF Datasheet Text Ellipsis Doesn't Work

I have a column with long user comments. I download it with the following code ...

<my:DataGridTextColumn Header="Message"
                       Binding="{Binding UserMessage, Mode=OneWay}" 
                       CanUserSort="True">
    <my:DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}"
               BasedOn="{StaticResource {x:Type TextBlock}}">
               <Setter Property="TextWrapping"
                       Value="NoWrap" />
               <Setter Property="TextTrimming"
                       Value="CharacterEllipsis"/>                                    
               <Setter Property="ToolTip"
                       Value="{Binding Path=UserMessage, Mode=OneWay}"/>
        </Style>
    </my:DataGridTextColumn.ElementStyle>
</my:DataGridTextColumn>

But the ellipsis will not work. The column continues to display long data text. In addition, when I set the width of the text block explicitly to some value, the ellipsis works fine, but when I resize my column, it will not display more text in it.

Is there any way to do this?

Thanks Vinet Sanke.

+3
source share
2 answers

Try setting the width of columns for which only static width is required. In this column you set the width to "*"

<my:DataGridTextColumn Header="Message"
                       Binding="{Binding UserMessage, Mode=OneWay}" 
                       CanUserSort="True"
                       Width="*">
    <my:DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}"
               BasedOn="{StaticResource {x:Type TextBlock}}">
               <Setter Property="TextWrapping"
                       Value="NoWrap" />
               <Setter Property="TextTrimming"
                       Value="CharacterEllipsis"/>                                    
               <Setter Property="ToolTip"
                       Value="{Binding Path=UserMessage, Mode=OneWay}"/>
        </Style>
    </my:DataGridTextColumn.ElementStyle>
</my:DataGridTextColumn>

, Google . ( "" ) . MinWidth, , .

+5

. , :

0

Source: https://habr.com/ru/post/1760249/


All Articles