不幸的是,这个问题比标题中描述的要复杂一些。带有 MediaElement 的页面并没有真正脱落,但仅在大约四分之一的情况下。
<Page
x:Class="Controls.Controls.VideoPlayerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Controls.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid >
<MediaElement AreTransportControlsEnabled="True"/>
</Grid>
</Page>
public sealed partial class VideoPlayerPage : Page
{
public VideoPlayerPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.InitializeComponent();
base.OnNavigatedTo(e);
}
}
<Page
x:Class="Controls2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Controls2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="Sp">
</Grid>
</Page>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
F();
}
public async void F()
{
for (int i = 0; i < 10; i++)
{
AppWindow appWindow = await AppWindow.TryCreateAsync();
Frame appWindowContentFrame = new Frame();
appWindowContentFrame.NavigateToType(typeof(VideoPlayerPage), null, null);
ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
await appWindow.TryShowAsync();
}
}
}
同时,例如,如果创建的页面中有一个按钮(而不是 MediaElement),则一切正常。