标签:header tap read val metadata key protected resource class
一、采用代理
1、xaml的Resources中添加一个FrameworkElement的代理
<Window.Resources>
<FrameworkElement x:Key="Proxy" DataContext="{Binding}"/>
</Window.Resources>
2、用一个隐藏的ContentControl绑定FrameworkElement代理
<ContentControl Visibility="Collapsed" Content="{StaticResource Proxy}"/>
3、用代理做Visibility的数据源
<DataGridTextColumn Header="列二" Visibility="{Binding DataContext.IsVisibility,Source={StaticResource Proxy}}"/>
二、使用Freezable
BindingProxy类
public class BindingProxy:Freezable
{
protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
//throw new NotImplementedException();
}
public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
public object Data
{
get { return (object)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
}
XAML引用BindingProxy
<local:BindingProxy x:Key="proxy" Data="{Binding}"/>
Visibility绑定
<DataGridTextColumn Header="列三" Visibility="{Binding Data.IsVisibility,Source={StaticResource proxy}}"/>
标签:header tap read val metadata key protected resource class
原文地址:https://www.cnblogs.com/vagrant-boy/p/12515913.html