To reference media element events located on a ContentView from a ContentPage XAML CS class, you can declare the media element as a public property in the ContentView. Then, you can access the media element from the ContentPage by getting a reference to the ContentView and accessing its public property.
For example, in the ContentView XAML:
<ContentView>
<MediaElement x:Name="myMediaElement" />
</ContentView>
In the ContentView CS class:
public partial class MyContentView : ContentView
{
public MediaElement MyMediaElement => myMediaElement;
}
In the ContentPage XAML:
<ContentPage>
<local:MyContentView x:Name="myContentView" />
</ContentPage>
In the ContentPage CS class:
public partial class MyContentPage : ContentPage
{
private MyContentView _myContentView;
public MyContentPage()
{
InitializeComponent();
_myContentView = myContentView;
_myContentView.MyMediaElement.MediaEnded += OnMediaEnded;
}
private void OnMediaEnded(object sender, EventArgs e)
{
// Media element ended event handler
}
}
This way, you can access the media element events located on a ContentView from a ContentPage XAML CS class.
Asked: 2021-08-18 11:00:00 +0000
Seen: 14 times
Last updated: Jun 21 '22