【发布时间】:2011-12-27 17:20:21
【问题描述】:
我有一个使用 MVVM 框架实现的 WPF 应用程序,该框架使用 ActiveX 控件,我需要保持 WPF 和 ActiveX UI 同步。
到目前为止,当我使用从文章 Hosting an ActiveX Control in WPF 和这篇 question 中获得的问题底部的代码更改 WPF UI 时,我可以更新 ActiveX UI。
但是当我在 ActiveX UI 中进行更改时,我无法更新 WPF UI。
我怀疑我需要从我的 ActiveX 控件中触发 PropertyChanged 事件,但我不知道如何执行此操作,或者是否有可能。
我编写的 ActiveX 控件是在 VB6 和 MFC 中编写的,因为此时我只是在制作原型,以便最终将 VB6 ActiveX 控件集成到 WPF 容器应用程序中。
这是一个代码片段,显示了到目前为止所做的工作:
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
// Create the ActiveX control.
AxTEXTBOXActiveXLib.AxTEXTBOXActiveX axWmp = new AxTEXTBOXActiveXLib.AxTEXTBOXActiveX();
// Assign the ActiveX control as the host control's child.
host.Child = axWmp;
axWmp.DataBindings.Add(new System.Windows.Forms.Binding("ActiveXStatus", (MainWindowViewModel)this.DataContext, "ModelStatus", true, DataSourceUpdateMode.OnPropertyChanged ));
// Add the interop host control to the Grid
// control's collection of child controls.
this.activexRow.Children.Add(host);
如何在 ActiveX 控件和 WPF MVVM 视图模型之间实现双向绑定?
【问题讨论】: