In my app I have a page with a GridView with a DataTemplate that has a MediaPlayer element that is bound to a list of sources. Each MediaPlayer element has to stop playing when the user leaves the page. I wanted to solve this by pausing the MediaPlayers when the user clicks a button that goes to another page, but I can't get my head around on how to pause the players when they are generated by the GridView.
How do I reach each instance of the MediaPlayer to be able to pause them?
<GridView Name="Gridview" Grid.Row="1" ItemsSource="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center" SelectionMode="None">
<GridView.ItemTemplate>
<DataTemplate x:DataType="local:TutorialVideo">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding Title}" Style="{ThemeResource SubheaderTextBlockStyle}" Margin="10"/>
<MediaPlayerElement Name="player" MinWidth="500" MaxWidth="800" AreTransportControlsEnabled="True" Source="{Binding Source}" Margin="10"/>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>