Reputation: 423
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.
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.
Even the slightest attempt like the below causes unhandled win32 errors:
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?
Upvotes: 2
Views: 3749
Reputation: 423
Okay, so I figured it out myself. I found this page which put me onto the right path: 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.
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))
}
}
}
}
});
}
}
Upvotes: 6