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

    }

相关文章:

  • 2022-01-04
  • 2021-11-08
  • 2021-11-05
  • 2022-12-23
  • 2021-12-20
  • 2021-07-17
  • 2021-07-09
  • 2022-01-16
猜你喜欢
  • 2021-10-01
  • 2022-02-25
  • 2022-12-23
  • 2022-03-02
  • 2021-06-08
  • 2021-09-20
  • 2022-12-23
相关资源
相似解决方案