如何将ActiveX控件关联到事件/更改到我的ViewModel中? [英] How to hook ActiveX control into events/changes into my viewmodel?

查看:127
本文介绍了如何将ActiveX控件关联到事件/更改到我的ViewModel中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将WindowsMediaPlayer ActiveX添加到我的WPF / MVVM应用程序中。现在,我需要控件对视图模型中发生的更改做出反应(最重要的是,当我的集合中的当前选择发生更改时更新URL)。基于演练:在WPF中托管ActiveX控件我在我的已加载事件:

I've added WindowsMediaPlayer ActiveX to my WPF/MVVM application. Now I need the control to react to changes happening in the viewmodel (most importantly updating URL when the current selection in my collection changes). Based on Walkthrough: Hosting an ActiveX Control in WPF I have the following in my Loaded event:

// 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);

问题是-如何在视图模型中的属性更改时更新axWMP.URL控件属性?

Question is - how do I update the axWMP.URL control property on a property change in my viewmodel?

推荐答案

好,使用Windows.Forms.Binding:

Ok, used Windows.Forms.Binding:

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

这篇关于如何将ActiveX控件关联到事件/更改到我的ViewModel中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆