WPF ListView,如果下一列为空,则文本不会被剪切 [英] WPF ListView with text not clipped if next column is empty

查看:111
本文介绍了WPF ListView,如果下一列为空,则文本不会被剪切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的多列ListView中,某些列在第一列中具有非常大的文本,但在随后的所有列中都没有文本(我称它们为"HeaderRows"),而在下面的某些行中,所有列均填充有一些简短的纹理信息.

我的问题是,所有HeaderRows的第一列都被裁剪.

在Excel中,有一个解决方案,只有填充的单元格才能剪切单元格左侧的内容.

有谁知道如何使用ListView实现这种行为?

在此先感谢德国的问候,

Helmut

Hi,
In my multi column ListView I have certain rows with a very large text in the first column, but no text in all the following columns (I call them "HeaderRows") and below I have some rows where all columns are filled with some short textural information.

My problem is, that the first column of all the HeaderRows is clipped.

In Excel there is a solution that only populated cells will clip the content of the cell on it''s left side.

Does anyone have an idea how such a behaviour can be achieved with a ListView?

Thanks in advance and greetings from germany,

Helmut

推荐答案

如果您正在使用GridView进行操作,我不知道该小问题的解决方案...

但是,如果您深入研究ItemTemplate并自己处理列,则可以在...中破解类似的内容.
If you''re doing it with a GridView, I don''t know of a solution to that little issue...

But if you delve into the ItemTemplate and handle the columns yourself, you might be able to hack something like that in...
<ListView.ItemTemplate>
  <DataTemplate DataType="...">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="..."/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <TextBlock Grid.Column="0" Text="{Binding col0Text}"

                 Grid.ColumnSpan="{Binding col1Text,Converter={StaticResource cnvOneOrTwo}"

      />
      <TextBlock Grid.Column="1" Text="{Binding col1Text}"/>
      <TextBlock Grid.Column="2" Text="{Binding col2Text}"/>
    </Grid>
  </DataTemplate>
</ListView.ItemTemplate>


(注意:此处输入了代码,因此未经测试/调试)

基本上,创建一个自定义IValueConverter,它将NEXT列的内容作为参数,如果已填充,则返回1,如果为空,则返回2.您甚至可以传递整个绑定记录,然后让转换器检查每个列中的数据并确定正确的ColumnSpan.

它不是单行解决方案,但可以解决问题.


(Note: Code entered here, so not tested/debugged)

Basically, create a custom IValueConverter that would take the contents of the NEXT column as an argument, and return 1 if it''s populated or 2 if it''s empty. You could even pass the entire bound record, and have your converter check each column for data and determine the correct ColumnSpan.

It''s not a one-line solution, but it might do the trick.


这篇关于WPF ListView,如果下一列为空,则文本不会被剪切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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