我在WindowsFormsHost中的DataGridView周围有一个usercontrol包装器。
包装器有一个带回调的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));
答案 0 :(得分:1)
WPF传递其属性在source
参数中更改的实例
您可以将此参数强制转换为类型并获取字段。
var me = (MyControl)source;
me._gridView.GetData((LiteTable)e.NewValue);