[英]WPF ListView Star (“*”) size
I would like to fill the remaining area of a WPF ListView
with a certain column. 我想用某个列填充WPF
ListView
的剩余区域。
I have been googling around and found the following solution: 我一直在谷歌上搜索并找到以下解决方案:
<GridViewColumn Header="Error" DisplayMemberBinding="{Binding ErrorDescription}"
Width="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ListView}}, Converter={StaticResource WidtConvert}} />
And the converter: 和转换器:
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
ListView l = value as ListView;
GridView g = l.View as GridView;
double total = 0;
for (int i = 0; i < g.Columns.Count - 1; i++)
{
total += g.Columns[i].ActualWidth;
}
return (l.ActualWidth - total);
}
But the problem is that at the time that the converter is called, all columns including the ListView.ActualWidth
is 0. 但问题是,在调用转换器时,包括
ListView.ActualWidth
在内的所有列都是0。
I do not want to use any code behind for example on the Listview_SizeChanged
etc. 我不想在
Listview_SizeChanged
等上使用任何代码。
您可以将转换器从代码绑定到ListView控件的Loaded事件上的Width属性。在这种情况下,转换器将在控件完全加载并且实际宽度转移到转换器后被触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.