[英]dotNet MAUI Shell - Add Flyout Item in C#
I have an old App I wrote years ago in Xamarin and looking to update it to MAUI, and not a huge fan of writing Xaml.我有一个多年前在 Xamarin 中编写的旧应用程序,希望将其更新到 MAUI,而不是编写 Xaml 的忠实粉丝。
I know you can render pages with straight code, so I thought I would try this with Shell as well, but can't figure out the correct context for adding flyout items.我知道您可以使用直接代码呈现页面,所以我想我也会尝试使用 Shell,但无法找出添加弹出项的正确上下文。
Even the slightest attempt like the below causes unhandled win32 errors:即使像下面这样最轻微的尝试也会导致未处理的 win32 错误:
public partial class AppShell : Shell
{
public AppShell()
{
Items.Add(new FlyoutItem
{
Title = "test"
});
}
}
So I'm obviously going about it the wrong way.所以我显然以错误的方式去做。 What is the correct syntax?
正确的语法是什么?
Okay, so I figured it out myself.好的,所以我自己想通了。 I found this page which put me onto the right path: https://gist.github.com/TheBaileyBrew/f8a9d2e4668da3ec9bff9bf86d32d951
我发现这个页面让我走上了正确的道路: https://gist.github.com/TheBaileyBrew/f8a9d2e4668da3ec9bff9bf86d32d951
Anyway, so basically I was able to create an XAMLess AppShell.cs with essentially only this and it created the Shell instance, no problem.无论如何,所以基本上我能够创建一个 XAMLess AppShell.cs 基本上只有这个并且它创建了 Shell 实例,没问题。
public partial class AppShell : Shell
{
public AppShell()
{
Routing.RegisterRoute(nameof(MainPage), typeof(MainPage));
Items.Add(new FlyoutItem
{
Title = "Home",
Route = x.Route,
Icon = new FontImageSource
{
FontFamily = "fasolid900",
Glyph = FontAwesome.FontAwesomeIcons.Home,
},
Items =
{
new Tab{
Title = "Home",
Items = {
new ShellContent
{
Title = "Home",
Route = nameof(MainPage),
ContentTemplate = new DataTemplate(typeof(MainPage))
}
}
}
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.