2011-08-10 7 views
0

WindowsFormsHostのDataGridViewの周囲にユーザーコントロールラッパーがあります。DPコールバックからWindowsFormsHostコントロールを更新するWPF

ラッパーにはコールバック付きの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)); 

答えて

1

WPFは、そのプロパティsourceパラメータで変更インスタンスを渡します。
このパラメータを型にキャストしてフィールドを取得できます。

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

ありがとう、それは完璧に動作します! – ChandlerPelhams

関連する問題