簡體   English   中英

dotNet MAUI Shell - 在 C# 中添加彈出項目

[英]dotNet MAUI Shell - Add Flyout Item in C#

我有一個多年前在 Xamarin 中編寫的舊應用程序,希望將其更新到 MAUI,而不是編寫 Xaml 的忠實粉絲。

我知道您可以使用直接代碼呈現頁面,所以我想我也會嘗試使用 Shell,但無法找出添加彈出項的正確上下文。

即使像下面這樣最輕微的嘗試也會導致未處理的 win32 錯誤:

public partial class AppShell : Shell
{
    public AppShell()
    {
        Items.Add(new FlyoutItem
        {
            Title = "test"
        });
    }
}

所以我顯然以錯誤的方式去做。 正確的語法是什么?

在此處輸入圖像描述

好的,所以我自己想通了。 我發現這個頁面讓我走上了正確的道路: https://gist.github.com/TheBaileyBrew/f8a9d2e4668da3ec9bff9bf86d32d951

無論如何,所以基本上我能夠創建一個 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM