Global MediaElement that continues playing after navigating to other page

邮差的信 提交于 2019-11-30 07:39:18

It's possible your Navigated handler where you try to get the visual tree child gets called before the visual tree is fully loaded (added to visual tree). You could try moving your code to the Loaded event handler.

EDIT*

I confirmed my theory by making the following change:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        this.Loaded += OnLoaded;
    }

    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        DependencyObject rootGrid = VisualTreeHelper.GetChild(Window.Current.Content, 0);
        MediaElement rootMediaElement = (MediaElement)VisualTreeHelper.GetChild(rootGrid, 0);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!