如何在.NET MAUI中创建一个非Shell应用程序?

huangapple go评论68阅读模式
英文:

How to create a NON Shell App in .NET MAUI?

问题

我们已经做出了一个决定,使用Shell导航有点受限制和繁琐,我们打算使用我们自己的Flyout页面,但Shell应用程序中不允许使用它们。但是,当我们尝试创建一个新的应用程序时,没有选项来创建一个带有Shell或不带Shell的应用程序?所以我们创建了默认的应用程序,然后简单地删除了AppShell对象,这似乎可以工作,但是我们需要做的就只有这些吗,才能使用我们自己的Flyout页面吗?

英文:

We have made a decision that using Shell navigation is just a little restrictive and cumbersome and we are going to utilize our own Flyout pages which are not allowed in shell apps BUT when we move to create a new app, there is no option to create a shell/non shell app??? So we created default app then simply deleted the appshell object which seems to work BUT is this all that is required in order for us to utilize our own flyout pages?

答案1

得分: 1

以下是翻译好的部分:

"Its as simple as changing MainPage = new AppShell();in App.xaml.cs, to whatever you want:"
这就是更改 App.xaml.cs 中的 MainPage = new AppShell();,到你想要的任何内容:

"MainPage = new NavigationPage(new MyFirstPage());"
如果你想要使用 NavigationPage 的导航功能。

"Otherwise simply MainPage = new MyFirstPage();, and then roll your own page changes via Application.Current.MainPage = a SomeOtherPage();."
否则,只需 MainPage = new MyFirstPage();,然后通过 Application.Current.MainPage = a SomeOtherPage(); 自行更改页面。

"Substitute the appropriate class name for MyFirstPage. E.g. in the Maui template, it is class MainPage, so use MainPage if you want to immediately test a new Maui project."
用适当的类名替代 MyFirstPage。例如,在 Maui 模板中,它是 class MainPage,所以如果你想立即测试一个新的 Maui 项目,可以使用 MainPage

"Note that both these solutions involve explicitly calling new YourPageNameHere() rather than relying on Dependency Injection. This may affect code you need to write elsewhere (compared to Maui examples you'll find, which tend to rely on DI)."
请注意,这两种解决方案都涉及显式调用 new YourPageNameHere() 而不是依赖于依赖注入。这可能会影响你需要在其他地方编写的代码(与你可能会找到的依赖于 DI 的 Maui 示例相比)。

英文:

Its as simple as changing MainPage = new AppShell();in App.xaml.cs, to whatever you want:

  • MainPage = new NavigationPage(new MyFirstPage()); if you want to use NavigationPage's navigation features.
  • Otherwise simply MainPage = new MyFirstPage();, and then roll your own page changes via Application.Current.MainPage = new SomeOtherPage();.

Substitute the appropriate class name for MyFirstPage. E.g. in the Maui template, it is class MainPage, so use MainPage if you want to immediately test a new Maui project.

Note that both these solutions involve explicitly calling new YourPageNameHere() rather than relying on Dependency Injection. This may affect code you need to write elsewhere (compared to Maui examples you'll find, which tend to rely on DI).

huangapple
  • 本文由 发表于 2023年5月14日 21:27:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定