Manipulation events of MediaElement not fire when

2019-08-30 08:47发布

问题:

When I set player not in fullscreen (player.IsFullWindows = false), event work normally but when change player to full screen all manipulation event not work. Anyone have solution?

                <MediaElement Name="player"
                              Margin="10,5" ManipulationCompleted="player_ManipulationCompleted"
                              ManipulationDelta="Grid_ManipulationDelta"
                              ManipulationMode="TranslateX"
                              >

回答1:

I can reproduce this scenario by enabling both the IsFullWindow="True" and the AreTransportControlsEnabled="True". I think it makes sense, because when we are in the Full Window mode, it will go to the new layer named FullWindowMediaRoot instead of the MediaElement. Inside the FullWindowMediaRoot, it is the MediaTransportControls. You can see that clearly by using the Live Visual Tree as following:

So when we are in the Full Window mode, we need to handle the manipulation event of the TransportControls instead of the manipulation event of the MediaElement as following:

public MainPage()
    {
        this.InitializeComponent();
        player.TransportControls.ManipulationMode = ManipulationModes.TranslateX;
        player.TransportControls.ManipulationDelta += TransportControls_ManipulationDelta;
        player.TransportControls.ManipulationCompleted += TransportControls_ManipulationCompleted;

    }

    private void TransportControls_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {

    }

    private void TransportControls_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {

    }

Thanks.