简体   繁体   English

在datagrid文本框WPF中显示缺少的文本部分

[英]Show missing part of text in datagrid textbox 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. 在那里,您会看到一些太长的字符串值被切除。

This is the xaml code of text-boxes in data-grid. 这是数据网格中文本框的xaml代码。

<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>

You can set TextTrimming to CharacterEllipsis on TextBlock to show ellipse in case text is larger than available size. 您可以在TextBlock TextTrimming设置为CharacterEllipsis ,以在文本大于可用大小的情况下显示椭圆。

Also, you can show the complete text in Tooltip . 另外,您可以在Tooltip显示完整的文本。 This is how you do it for one DataGridTextColumn : 这是您对一个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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM