2011-08-10 51 views
0

我在WindowsFormsHost的DataGridView中有一個用戶控件包裝器。從DP回調中更新WindowsFormsHost控件WPF

包裝器有一個帶回調的DP,但回調是靜態的,所以它不能簡單地在windowsforms託管的控件上執行具有x:Name的代碼。

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

我想要做這樣的事情,但我不能在DP回調

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參數改變實例的引用_gridView。
您可以將此參數轉換爲您的類型並獲取該字段。

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

謝謝你,完美的作品! – ChandlerPelhams

相關問題