在datagrid文本框WPF中显示缺少的文本部分 [英] Show missing part of text in datagrid textbox WPF

查看:115
本文介绍了在datagrid文本框WPF中显示缺少的文本部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个数据网格,将字符串放入其中之后,其中一部分就不合适了,因为它们太长了。我希望文本框列的大小固定,因此我不想对文本框使用自动宽度属性,但是我想知道:是否可以使用某种属性来选择性地显示整个字符串?例如,如果:如果要长时间显示字符串,则可以容纳它的一部分,然后显示三个点(...)或类似的符号。单击三个点后,将显示文本框的整体价值。甚至在滚动某些文本框后甚至显示整个字符串。

I have one data-grid in my project, and after getting strings into it one part of them can't fit, because they are too long. I want that my text-box columns have fixed size, so I don't wanna use "auto" width property for text-box, but I was wondering: Is there some kind of property that I can use for showing whole string optionally? Like for example: If string is to long show the part of it you can fit, and after that show three dots (...) or some symbol like that. After clicking on three dots show whole value of text-box. Or even showing a whole string after rolling over some text-box.

我的数据网格看起来像这样。

My data-grid looks like this.

在那里您会看到一些太长的字符串值被切掉。

There you can see that some too long string values are cut of.

这是数据中文本框的xaml代码-grid。

This is the xaml code of text-boxes in data-grid.

<DataGrid Grid.Column="0" Grid.RowSpan="2" AutoGenerateColumns="False" Height="206" HorizontalAlignment="Left" Margin="12,265,0,0" Name="tabela" VerticalAlignment="Top" Width="556" SelectionChanged="tabela_SelectionChanged" ItemsSource="Binding MyObsCollection">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Type" Width="120" Binding="{Binding Type}"/>
        <DataGridTextColumn Header="MapTo" Width="120" Binding="{Binding MapTo}"/>
        <DataGridTextColumn Header="Name" Width="116" Binding="{Binding Name}"/>
    </DataGrid.Columns>     
</DataGrid>


推荐答案

您可以设置 TextTrimming 到TextBlock上的 CharacterEllipsis 以在文本大于可用大小的情况下显示椭圆。

You can set TextTrimming to CharacterEllipsis on TextBlock to show ellipse in case text is larger than available size.

另外,您可以在 Tooltip 中显示完整的文本。这是对一个 DataGridTextColumn 的方式:

Also, you can show the complete text in Tooltip. This is how you do it for one DataGridTextColumn:

<DataGridTextColumn Width="20" Binding="{Binding Name}">
  <DataGridTextColumn.ElementStyle>
    <Style TargetType="TextBlock">
      <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
      <Setter Property="ToolTip" Value="{Binding Text, 
                                 RelativeSource={RelativeSource Self}}"/>
    </Style>
  </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

这篇关于在datagrid文本框WPF中显示缺少的文本部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆