强制调整 ListView 内 GridView 列的大小 [英] Force resize of GridView columns inside ListView
本文介绍了强制调整 ListView 内 GridView 列的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有 GridView
的 ListView
WPF 控件.当列的内容发生变化时,我想调整 GridView
列的大小.
I have a ListView
WPF control with a GridView
. I'd like to resize the GridView
columns when the content of the columns changes.
我有几个不同的数据集,但是当我从一个更改为另一个时,每列的大小都适合之前的数据.我想动态更新.我该怎么做?
I have several distinct data sets but when I change from one to another, the size of each columns fits the previous data. I'd like to update dynamically. How can I do that?
推荐答案
最后,关于这个的一些结果.我找到了一种方法来执行与最初以及双击列标题上的夹具时相同的自动调整大小.
Finally, some results on this one. I've found a way to do the same auto-sizing that is done initially and when the gripper on a column header is double clicked.
public void AutoSizeColumns()
{
GridView gv = listView1.View as GridView;
if (gv != null)
{
foreach (var c in gv.Columns)
{
// Code below was found in GridViewColumnHeader.OnGripperDoubleClicked() event handler (using Reflector)
// i.e. it is the same code that is executed when the gripper is double clicked
if (double.IsNaN(c.Width))
{
c.Width = c.ActualWidth;
}
c.Width = double.NaN;
}
}
}
这篇关于强制调整 ListView 内 GridView 列的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文