Click here to Skip to main content
13,597,813 members
Rate this:
Please Sign up or sign in to vote.
See more:
Can System.Windows.Interactivity and Microsoft.Expression.Interactions (ExpressionBlend SDK) be used to setup and handle both dependency properties and routed events denoted by the wrench symbol and the lighting symbol in Visual Studio 2012?

I have a obtained a sample of a window that contains a textbox when the textbox is changed (dependency property) a method MyMethod in class MyViewModel : INotifyPropertyChanged is invoked. This is close to what I want.

Also in the window is a MediaElement where the event MediaOpened="mediaPlayer1_MediaEnded_1" (routed event) is handled in the code behind:
class MainWindow : Window

I’m trying to comply with MVVM style.

How should the xaml and c# code be modified such that the routed event MediaOpened is handled in class MyViewModel?

Posted 1-Feb-13 4:45am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your problem is that you can't bind to a View-level event from a view-model. That breaks the no-visual-dependency rule for the view model. So you have to covert the routed event into a command.

The most common way to work around this is to use the EventToCommand class in the MVVMLight toolkit. It is the easiest way to do it. However, there is a similar function in the Blend libraries if you don't want to use MVVMLight. It is in the Interactivity namespace. This link should help:[^]

Either way you will get the same result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02-2016 | 2.8.180621.3 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100