用依赖属性包装
我有一个 Windows 窗体控件,我使用 WindowsFormsHost 派生类对其进行包装,以访问 WPF 的数据绑定功能。 Forms 控件公开指示其状态的属性以及标准属性更改事件通知程序。
例如,Forms 控件上的 Zoom
属性伴随有 ZoomChanged
事件。在 WindowsFormsHost
包装器中,我使用 DependencyProperty
来表示基础 Windows 窗体控件属性。使用 PropertyMetaData
赋值回调按预期绑定到控件;但是,我不确定如何正确地将属性更改从包装的控件传播回绑定订阅者(即,Windows 窗体控件更改其 Zoom
属性并引发 ZoomChanged
事件)。关于如何实现这一目标有什么想法吗?我应该使用不同的方法吗?
I've got a Windows Forms control that I'm wrapping with a WindowsFormsHost
-derived class to access WPF's data binding functionality. The Forms control exposes properties that indicate its state, along with the standard property-changed event notifier.
For example, a Zoom
property on the Forms control is accompanied with a ZoomChanged
event. In the WindowsFormsHost
wrapper, I'm using a DependencyProperty
to represent the underlying Windows Forms control property. Binding works as expected going to the control using a PropertyMetaData
assignment callback; however, I'm not sure how to correctly propagate property changes from the wrapped control back out to binding subscribers (i.e., the Windows Form control changes its Zoom
property and raises the ZoomChanged
event). Any ideas on how to accomplish this? Should I be using a different approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认 Zoom 依赖属性使用双向绑定,一切正常。噢!
Defaulted the Zoom dependency property to use two-way binding and everything works. D'oh!