【问题标题】:Update WindowsFormsHost Control from DP Callback WPF从 DP 回调 WPF 更新 WindowsFormsHost 控件
【发布时间】:2011-08-10 17:28:59
【问题描述】:

我在 WindowsFormsHost 中的 DataGridView 周围有一个用户控件包装器。

包装器有一个带有回调的 DP,但回调是静态的,因此它不能简单地在具有 x:Name 的 windowsforms 托管控件上执行代码。

如何在 DP 更新时更新 WindowsFormsHost DataGridView?

我想做这样的事情,但我无法在 DP 回调中引用 _gridView

 public LiteTable GridViewData
    {
        get { return (LiteTable)GetValue(GridViewDataProperty); }
        set { SetValue(GridViewDataProperty, value); }
    }

    private static void OnGridViewDataChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
    {
        _gridView.GetData((LiteTable)e.NewValue);
    }

    // Using a DependencyProperty as the backing store for GridViewData.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty GridViewDataProperty =
        DependencyProperty.Register("GridViewData", typeof(LiteTable), typeof(LiteGridViewWrapper), new UIPropertyMetadata(null, OnGridViewDataChanged));

【问题讨论】:

    标签: wpf mvvm binding dependency-properties


    【解决方案1】:

    WPF 传递在source 参数中其属性发生变化的实例。
    您可以将此参数强制转换为您的类型并获取该字段。

    var me = (MyControl)source;
    me._gridView.GetData((LiteTable)e.NewValue);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      • 2020-01-07
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多