WPF数据网格文本省略号不起作用 [英] WPF Data grid Text Ellipsis Not working
问题描述
< 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>
但省略号不起作用。该列继续显示长文本的数据。此外,当我将textblock的宽度显式设置为某个值时,省略号可以正常工作,但是当我调整列的大小时,它不会再显示任何文本。
不在那里一个这样做的一个最好的方法?
Thx
Vinit Sankhe。
尝试设置您的列上只需要静态宽度的宽度。在此列中,将宽度设置为*
< my:DataGridTextColumn Header =Message
绑定={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,以确保当窗口调整大小时,列不会被压缩为无。
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.
这篇关于WPF数据网格文本省略号不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!