2010-10-09 19 views
1

J'ai ajouté WindowsMediaPlayer ActiveX à mon application WPF/MVVM. Maintenant, j'ai besoin du contrôle pour réagir aux changements qui se produisent dans le viewmodel (le plus important est de mettre à jour l'URL lorsque la sélection actuelle dans ma collection change). Sur la base Walkthrough: Hosting an ActiveX Control in WPF je le suivais dans mon événement Loaded:Comment accrocher le contrôle ActiveX dans les événements/changements dans mon viewmodel?

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

La question est - comment puis-je mettre à jour la propriété de contrôle de axWMP.URL sur un changement de propriété dans mon viewmodel?

Répondre

1

Ok, utilisé Windows.Forms.Binding:

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

Cela fonctionnait très bien de mettre à jour le contrôle ActiveX du ViewModel, mais avez-vous déjà mis à jour la vue Modèle du contrôle ActiveX et si oui, comment? – Zamboni