我有一个显示大量对象的数据表格。这些对象具有一个属性IsDetailsExpanded
,我想将数据行的DetailsVisibility
属性绑定到该属性。
我的第一种方法可行,但需要一些代码后台处理(我希望摆脱它)。
我处理LoadingRow
事件。
void LoadingRowHandler(object sender, DataGridRowEventArgs e)
{
Binding b = new Binding()
{
Source = e.Row.DataContext,
Path = new PropertyPath("IsExpanded"),
Converter = (IValueConverter)Resources["BoolToVisi"],
Mode = BindingMode.TwoWay
};
e.Row.SetBinding(DataGridRow.DetailsVisibilityProperty, b);
}
我认为在XAML中一定有一种类似的方法实现这个功能,但不幸的是我毫无头绪。 有任何想法或建议吗?
{Binding RelativeSource={RelativeSource Self}, Path=DataContext.IsExpanded, Converter={StaticResource BoolToVisi}}
,但我不认为会有问题。 - CodeNaked