简体   繁体   English

WInUI 3.0 桌面 - 尝试导航时出现异常崩溃

[英]WInUI 3.0 Desktop - Crash on exception when try to navigate

I want to change frame, but I get this exception:我想改变框架,但我得到了这个例外:

例外

Navigation:导航:

Frame rootFrame = new Frame();
rootFrame.Navigate(typeof(ScoreWindow), null, new EntranceNavigationTransitionInfo());

Exception appears on constructor:构造函数上出现异常:

        public ScoreWindow()
        {
            this.InitializeComponent();
            results = new List<Result>();
            playerList = new();
            LoadData();
            var _resultsView = ConvertToView();
            sfDataGrid.ItemsSource = _resultsView;
        }

Thanks for answers in advance and happy holidays!感谢您提前回答并祝您节日快乐!

PS Thanks to Raymond, I detected this message: PS 感谢 Raymond,我检测到了这条消息:

WinUI: Error creating second Desktop Window on the current process. No more than one Desktop Window is allowed per process.

There is another question: how to change current frame to other?还有一个问题:如何将当前帧更改为其他帧? I mean, I have login view, user logged in successfully and want to see data/other things.我的意思是,我有登录视图,用户成功登录并想查看数据/其他内容。

After a little break, I understood what I did wrong.稍作休息后,我明白我做错了什么。 There is a way how to navigate between pages.有一种方法可以在页面之间导航。

Rule #1: In WinUI, you have only one active window, and it's MainWindow.规则 #1:在 WinUI 中,您只有一个活动的 window,它是 MainWindow。 Always.总是。 If you want to change layout, you have to use Frames.如果你想改变布局,你必须使用框架。

In MainWindow.xaml, you write this:在 MainWindow.xaml 中,您可以这样写:

    <Grid>
        <Frame x:Name="mainFrame"/>
    </Grid>

Element "Frame" give ability to navigate between pages.元素“框架”提供在页面之间导航的能力。

Then switch to MainWindow.xaml.cs and in constructor have to be something like this:然后切换到 MainWindow.xaml.cs 并且在构造函数中必须是这样的:

        public MainWindow()
        {
            InitializeComponent();
            mainFrame.Navigate(typeof(NameOfYourPage));
        }

It will immediately activate your page.它将立即激活您的页面。

Then, if you want to navigate from page to page, write in control of page this:然后,如果您想从一个页面导航到另一个页面,请在页面控制中写入:

Frame.Navigate(typeof(NameOfYourPage), null, new EntranceNavigationTransitionInfo());

The third parameter is animation, but I didn't notice changes.第三个参数是animation,但是我没有注意到变化。

More information you can find here:您可以在此处找到更多信息:

Tutorial about navigation 关于导航的教程

Microsoft documentation 微软文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM