I understand that ViewModel shouldn’t have any knowledge of View, but how can I call MediaElement.Play() method from ViewModel, other than having a reference to View (or directly to MediaElement) in ViewModel?
Other (linked) question: how can I manage View’s controls visibility from ViewModel without violating MVVM pattern?
I understand that ViewModel shouldn’t have any knowledge of View, but how can I
Share
1) Do not call
Play()from the view model. Raise an event in the view model instead (for instancePlayRequested) and listen to this event in the view:view model:
view:
2) You can expose in the view model a public boolean property, and bind the
Visibilityproperty of your controls to this property. AsVisibilityis of typeVisibilityand notbool, you’ll have to use a converter.You can find a basic implementation of such a converter here.
This related question might help you too.