We then do few things in the DemoView.XAML: Implement the IMediaService in the View: public partial class DemoView : UserControl, IMediaService Introduce an interface called IMediaService as below: public interface IMediaService ![]() In short, we are going to introduce an interface between the View and the ViewModel to break the dependecy, and the View will be implementing the interface and be responsible for the direct controlling of the MediaElement while leaving the ViewModel talking only to the interface, which can be swapped with other implementation for testing purposes if needed, and here comes the long version: we want to use Command to do the magic here.the the MediaElement and the View itself. we don't want to have direct reference from the ViewModel to any UI elements, i.e.There are many ways to achieve the same result and it really depends on how you would like to implement yours, as long as your code is not difficult to maintain, I do believe it's ok to break the MVVM pattern under certain cases.īut having said that, I also believe there is always way to do this within the pattern, and the following is one of them just in case if anyone would like to know what other alternatives are available.
0 Comments
Leave a Reply. |