WPF 数据网格文本省略号不起作用
我有一个专栏,里面有很长的用户评论。我使用以下代码加载它...
<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>
但是省略号不起作用。该列继续显示长文本数据。此外,当我将文本块的宽度显式设置为某个值时,省略号可以正常工作,但是当我调整列大小时,它不会在其中显示更多文本。
难道没有一种直观的方法可以做到这一点吗?
谢谢 维尼特·桑赫。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在只需要静态宽度的列上设置宽度。在此列中,您将宽度设置为“*”,
我通过谷歌搜索您的问题找到了您的问题。我获取了您的代码,只是向我的列添加了宽度(“标题”列除外),并且能够正确放置省略号。我还添加了一个 MinWidth 只是为了确保当调整窗口大小时,该列不会被压扁。
Try setting widths on your columns that only need static widths. On this column you set the width to "*"
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.