MediaElement.play() from within ViewModel

前端 未结 3 2128
我寻月下人不归
我寻月下人不归 2021-02-09 21:45

I\'m struggling with the following issue:

I am building a WP8 application using the MVVM patern. I have a media element on my view.xaml and the logic to control this med

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-09 22:00

    You can bind Media Element directly from the view model

    in xaml:

    
    

    in ViewModel:

    private MediaElement _mediaElementObject;
    
    public MediaElement MediaElementObject
    {
       get { return _mediaElementObject; }
       set { _mediaElementObject = value;RaisePropertyChanged(); }
    }
    

    And on OnNavigatedTo Override method you can create it's new object & can register it's events.

    MediaElementObject=new MediaElement();
    

    So that you can do all thing from the viewmodel itself.

提交回复
热议问题