自动调整 WPF TreeListView 中的列大小
我正在尝试使用以下代码自动调整 WPF TreeListView (http://www.codeproject.com/KB/WPF/wpf_treelistview_control.aspx) 的列大小:
public void AutoResizeColumns()
{
GridView gv = this.View as GridView;
if (gv != null)
{
foreach (GridViewColumn gvc in gv.Columns)
{
if (double.IsNaN(gvc.Width))
gvc.Width = gvc.ActualWidth;
gvc.Width = double.NaN;
}
}
}
但是当我调整它的大小时,列宽度不考虑边距行和单词被截断了大约 10px,然后如果我双击该列,它将调整大小而不会截断单词。
我也尝试过,但没有成功:
public void AutoResizeColumns()
{
GridView gv = this.View as GridView;
if (gv != null)
{
foreach (GridViewColumn gvc in gv.Columns)
{
gvc.Width = gvc.ActualWidth + 10;
}
}
}
有人知道如何解决这个问题吗?
I am trying to auto resize the columns of WPF TreeListView (http://www.codeproject.com/KB/WPF/wpf_treelistview_control.aspx) using this code:
public void AutoResizeColumns()
{
GridView gv = this.View as GridView;
if (gv != null)
{
foreach (GridViewColumn gvc in gv.Columns)
{
if (double.IsNaN(gvc.Width))
gvc.Width = gvc.ActualWidth;
gvc.Width = double.NaN;
}
}
}
But when I resize it, the column width is not accounting for the margin of the row and the words are cut off by like 10px and then if I double click the column, it will resize without cutting off the words.
I have also tried this with no luck:
public void AutoResizeColumns()
{
GridView gv = this.View as GridView;
if (gv != null)
{
foreach (GridViewColumn gvc in gv.Columns)
{
gvc.Width = gvc.ActualWidth + 10;
}
}
}
Does anyone know how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几个小时的尝试解决这个问题,我终于明白了。列宽度被设置为 ActualWidth,它小于其应有的宽度,因此,如果我将列宽度设置为 double.MaxValue,那么当其设置为 double.NaN 时,它将调整大小为“真实”实际宽度。
这是代码:
After hours of trying to figure this out, I finally got it. The column Width is being set to ActualWidth which is less then its supposed to be, so if I set the column Width to double.MaxValue then when its set to double.NaN it will resize to the "real" actual width.
Here's the code: