![]() ![]() other commands are not listed, but you get the idea ![]() This.loadedCommand = new DelegateCommand((mediaService) => We now can catch everything in the ViewModel (I'm using prism's DelegateCommand here): public class AboutUsViewModel : SkinTalkViewModelBase, IConfirmNavigationRequest last but not least, we need to hookup the media controls through Commands:.Hookup the Loaded event through Trigger to pass the view itself to the view model through a Command.import the interactivity namespace for later use (some default namespaces are omitted for simplicity reason):.Give the view a name so we can pass it as a parameter, and.Give the MediaElement a name so the code behind can access it like above:.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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |