【问题标题】:WPF ListView Star ("*") sizeWPF ListView 星号(“*”)大小
【发布时间】:2013-01-22 09:53:10
【问题描述】:

我想用某个列填充 WPF ListView 的剩余区域。

我一直在谷歌搜索并找到以下解决方案:

<GridViewColumn Header="Error" DisplayMemberBinding="{Binding ErrorDescription}" 
   Width="{Binding RelativeSource={RelativeSource FindAncestor, 
   AncestorType={x:Type ListView}}, Converter={StaticResource WidtConvert}} />

还有转换器:

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);
}

但问题是,在调用转换器时,包括ListView.ActualWidth 在内的所有列都是0。

我不想在 Listview_SizeChanged 等后面使用任何代码。

【问题讨论】:

标签: c# wpf xaml


【解决方案1】:

您可以将转换器从后面的代码绑定到 ListView 控件的 Loaded 事件上的 Width 属性。在这种情况下,转换器将在控件完全加载并将实际宽度传输到转换器后触发。

【讨论】:

  • 你能举例说明如何将转换器绑定到加载的属性吗?
  • 抱歉这么晚才回复。我发现很难用 GridViewColumn 举例。我建议使用多转换器而不是转换器并将 ListView.ActualHeight 和转换器中使用的参数作为参数传递。所以在 ListView.ActualHeight 由 0 变为实际值后调用转换器。
猜你喜欢
  • 2011-03-18
  • 2020-10-13
  • 1970-01-01
  • 1970-01-01
  • 2010-12-21
  • 2011-09-14
  • 1970-01-01
  • 2013-06-24
  • 2014-08-23
相关资源
最近更新 更多