如何在包含回车符的WPF GridView中显示文本 [英] How to display text in a WPF GridView that contains carriage returns

查看:182
本文介绍了如何在包含回车符的WPF GridView中显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格视图,它有两个简单的列,一个报表编号和一个简短描述。这个简短的描述通常有一些回车。如果是这种情况,我希望该行扩展其高度以适合所有文本。



目前,该字段可能会显示第一行,但可能会显示第一行然后切断它下面的文字。我怎么能显示所有的文本,并根据需要调整高度?



这可以在每行的基础上完成,如果下一次报告没有与回车的描述,它只会显示在一行?



这将是类似于这个问题,但是在WPF和ASP.net之间, p>

这也可能是因为使用广泛的主题应用程序。如果是这样的话,我怎么才能在这个网格视图中执行它?



XAML:



我只是将它作为

 < GridViewColumn Width =365Header =DescDisplayMemberBinding ={Binding desc} /> 

我也曾尝试过

 < GridViewColumn x:Name =colDescHeader =DescWidth =75> 
< GridViewColumn.CellTemplate>
< DataTemplate>
< TextBlock Text ={Binding Desc}/>
< / DataTemplate>
< /GridViewColumn.CellTemplate>
< / GridViewColumn>

我们正在使用一个应用程序范围的主题,很可能会明确设置高。如果是这样,我主要倾向于这个事实(从评论),主题是否覆盖了它的工作原理的默认值。如果是这样,我该如何按照它应该的方式行事(再次,从评论中,这听起来像这是默认行为)。



使用第二个示例,如下所示:


在这里,它看起来像文字更大,所以再次,我希望细胞能够适应需要的高度。其中一些有多行,所以你可以看到我不会看到剩余的内容。我也尝试在文本块上设置高度,但这没有效果。

解决方案

这有效。

  public string TextBlockText {get {returnone line \r\\\
two line; }}

< TextBlock Height =AutoWidth =100Horizo​​ntalAlignment =LeftText ={Binding Path = TextBlockText}/>

我将给你介绍如何将TextBlock放入ListView中。


I have a grid view that has two simple columns, a report number and a short description. It is common for this short description to have some carriage returns. If that is the case, I would like the row to expand its height to fit all of the text in.

Currently the field renders with possibly the first line displaying, but then cutting off text below it. How could I display all the text, with it adjusting the height as needed?

And can this be done on a per-row basis, as in, if the next report did not have a description with carriage returns, it would just show on one line?

It would be rather similar to this question, but in WPF versus ASP.net

This also may due to using a theme application wide. If that is the case, how can I enforce it only in this grid view?

XAML:

Originally I had it only as

<GridViewColumn Width="365" Header="Desc" DisplayMemberBinding="{Binding desc}" />

I have also tried

<GridViewColumn x:Name="colDesc" Header="Desc" Width="75" >
     <GridViewColumn.CellTemplate>
          <DataTemplate>
              <TextBlock Text="{Binding Desc}" />
          </DataTemplate>
     </GridViewColumn.CellTemplate>
</GridViewColumn>

We are using an application wide theme, that very well may be setting the high explicitly. If so, I am leaning mostly towards the fact (From the comments) that the theme is overriding a default value for how this works. If so, how do I have it act the way the it is supposed to (again, from the comments, it sounds like this is the default behavior).

Using the second example, here is what it looks like:

In here it looks like the text is larger, so again, I would want the cell to adjust to the hight needed. And some of these have multiple lines, so as you can see I would not see the remaining content. I have also tried to set the Height on the text block, but that had no effect.

解决方案

This worked.

 public string TextBlockText { get { return "one line \r\ntwo line"; } }

 <TextBlock Height="Auto" Width="100" HorizontalAlignment="Left" Text="{Binding Path=TextBlockText}" />

I will leave it to you on how to put a TextBlock in a ListView.

这篇关于如何在包含回车符的WPF GridView中显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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