如何将ActiveX控件挂钩到事件/更改到我的viewmodel?

时间:2010-10-09 01:45:50

标签: mvvm activex viewmodel

我已将WindowsMediaPlayer ActiveX添加到我的WPF / MVVM应用程序中。现在我需要控件来响应viewmodel中发生的更改(最重要的是当我的集合中的当前选择发生更改时更新URL)。基于Walkthrough: Hosting an ActiveX Control in WPF我在Loaded事件中有以下内容:

// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();

// Create the ActiveX control.
AxWMPLib.AxWindowsMediaPlayer axWmp = new AxWMPLib.AxWindowsMediaPlayer();

// Assign the ActiveX control as the host control's child.
host.Child = axWmp;

// Add the interop host control to the Grid
// control's collection of child controls.
this.pnlMediaPlayer.Children.Add(host);

问题是 - 如何更新viewmodel中属性更改的axWMP.URL控件属性?

1 个答案:

答案 0 :(得分:1)

好的,使用了Windows.Forms.Binding:

axWmp.DataBindings.Add(new System.Windows.Forms.Binding("URL",(DisplayViewModel)this.DataContext,"Source"));