开发者

WPF Data grid Text Ellipsis Not working

I have a column with long user comments. I load it using 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 wont work. The column continues to display long text of data. Also when I set the width of the textblock explicitly to some value then the ellipsis work fine but when I resize my column it wont show any more text in it.

Isnt there a starighforward way to do this?

Thx Vinit Sankhe.


Try setting widths on your columns that only need static widths. On 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>

I found your question by Googling your question. I took your code and just added widths to my columns (except for a "Title" column) and was able to have it place the ellipsis correctly. I also added a MinWidth just to make sure that when the window is resized the column isn't squished to nothing.


Have a look at this article. It think it's the solution you're looking for:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜