微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 xamarin 表单 UWP 中使用 AppWindow 打开多个窗口?

如何解决如何在 xamarin 表单 UWP 中使用 AppWindow 打开多个窗口?

因为我使用“AppWindow”在 xamarin 表单 UWP 中打开单独的窗口。我尝试了下面的代码来打开窗口,

 if (appWindow == null)
        {
            appWindow = await AppWindow.TryCreateAsync();
            Frame appWindowFrame = new Frame();
            appWindowFrame.Navigate(typeof(testpage));
            ElementCompositionPreview.SetAppWindowContent(appWindow,appWindowFrame);
        }
        await appWindow.TryShowAsync();

当'Appwindow.TryCreateAsync'方法调用时,会抛出'Class not registered exception'。请看下面的片段,

enter image description here

我试图检查这个问题并试图找到解决方案。但我没有得到任何解决方案来解决这个问题。如果您遇到同样的问题或任何解决方案,请告诉我。

解决方法

请确保您的 testpage 扩展 Page

我创建了一个名为 AppWindowMainPage 的空白页面,如下图所示。

enter image description here

AppWindowMainPage.cs

  public sealed partial class AppWindowMainPage : Page
    {
        public AppWindowMainPage()
        {
            this.InitializeComponent();
        }
    }

AppWindowMainPage.xaml

<Page
    x:Class="App75.UWP.AppWindowMainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App75.UWP"
    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>
        <TextBlock Text="test"></TextBlock>
    </Grid>
</Page>

当我运行代码时,它可以打开一个新窗口。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。