SilverLight DataGrid 自定义列数据绑定 上下文代理器 DataContextProxy

时间:2021-01-05 19:18:02
public class DataContextProxy : FrameworkElement { public DataContextProxy() { this.Loaded += new RoutedEventHandler(DataContextProxy_Loaded); } void DataContextProxy_Loaded(object sender, RoutedEventArgs e) { Binding binding = new Binding(); if (!String.IsNullOrEmpty(BindingPropertyName)) { binding.Path = new PropertyPath(BindingPropertyName); } binding.Source = this.DataContext; binding.Mode = BindingMode; this.SetBinding(DataContextProxy.DataSourceProperty, binding); } public Object DataSource { get { return (Object)GetValue(DataSourceProperty); } set { SetValue(DataSourceProperty, value); } } public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register("DataSource", typeof(Object), typeof(DataContextProxy), null); public string BindingPropertyName { get; set; } public BindingMode BindingMode { get; set; } }