从 DP 回调 WPF 更新 WindowsFormsHost 控件
我在 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));
I have a usercontrol wrapper around a DataGridView in a WindowsFormsHost.
The wrapper has a DP with a callback, but the callback is static so it cannot simply execute code on the windowsforms hosted control that has an x:Name.
How can I update the WindowsFormsHost DataGridView when the DP gets updated?
I want to do something like this, but I cannot reference _gridView in the DP callback
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));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WPF 传递在
source
参数中属性发生更改的实例。您可以将此参数转换为您的类型并获取该字段。
WPF passes the instance whose property changed in the
source
parameter.You can cast this parameter to your type and get the field.