在 Android 的 .NET MAUI 内容页面之间移动的导航问题

Navigation issue of moving between content pages .NET MAUI for Android

您好,感谢您提前阅读... 我有一个项目旨在为一家皮划艇公司提供客户预订系统,并创建了初始登录页面,该页面可用于验证方面的所有意图和目的,但是当我单击登录按钮时[并且详细信息似乎已被验证,它不会转移到下一个内容页面 [查看]。 我附上了一段视频 link,展示了实践中的问题,但我希望能得到一些帮助,帮助我发现我错过了什么愚蠢的事情,因为我整晚和今天都在做这件事,并认为我已经走了对明显的东西有点盲目!? Navigation Issue Screen Recording

    private void BtnLogin_Clicked(object sender, EventArgs e)
{
    //shifty debug
    btnLogin.Text = "click received...";

    string user = entUsername.Text;
    string pass = entPassword.Text;
    string[] users = new string[result.Members.Length];
    string[] passes = new string[result.Members.Length];
    for (int i = 0; i < result.Members.Length; i++)
    {
        users[i] = result.Members[i].Usr;
        users[i] = result.Members[i].Pass;
    }

    if (user == string.Empty || pass == string.Empty)
    {
        InputError($"User: {user}\nPass: {pass}\n Nothing was entered in one of the text fields");
    }
    else
    {
        switch (user)
        {
            case "gruff":
                case "kieran":
                    case "zara":
                    {
                        NextPage();
                        break;
                    }
            default:
                InputError($"User: {user}\nPass: {pass}\n Not a correct user and/or password");
                break;
        }
    }
}
private void InputError(string v)
{
     Navigation.PushModalAsync(new InfoModal(v));
}
private void NextPage()
{
    btnLogin.Text = "At NextPage Method caledl";
    //so after a number of attempts to show a modal or next page 
    //some success with modal above, but possibly hangs after... i think
    //no success with content page change: the start for tomrorrow :/
    Navigation.PushAsync((new ClientMainPage()));
}

为了更清楚起见,下面是整个代码 sheet,但我认为是上面的代码被触发并产生了我认为有问题的结果:(

public partial class MainPage : ContentPage
{
    //simple admin cover fr viewing xml data
    private const string admin = "123";
    private bool revealState = true;
    private System.Xml.Serialization.XmlSerializer serializer;
    private XmlMemberData result;

    public MainPage()
    {
        InitializeComponent();
        GetMembers();
    }

    private async void GetMembers()
    {
        await using var stream = await FileSystem.OpenAppPackageFileAsync("Members.xml");

        serializer = new System.Xml.Serialization.XmlSerializer(typeof(XmlMemberData));

        result = (XmlMemberData)serializer.Deserialize(stream);

        IEnumerable<Member> members = result?.Members.ToList();
    }

    private void BtnMembersCheck_Clicked(object sender, EventArgs e)
    {    
        if(revealState)
        {
            string adminKey = entAdminKey.Text;

            if (adminKey != admin)
            {
                adminKey = "";
                entAdminKey.Text = string.Empty;

                //pop up a modal warning? - UX
                return;
            }

            var members = result?.Members.ToList();

            switch (members?.Count)
            {
                case 0:
                    StatusLabel.Text = "None Found, Are you sure you created any users?";
                    break;
                case > 0:
                    StatusLabel.Text = $"{members.Count} Members Loaded!";
                    BooksListControl.ItemsSource = members;
                    btnMembersCheck.Text = "ClearData";
                    revealState = !revealState;
                    break;
                default:
                    StatusLabel.Text = "Something went wrong";
                    break;
            }
        }
        else
        {            
            StatusLabel.Text = "To View Again Re-Enter Admin Key";
            entAdminKey.Text = string.Empty;
            btnMembersCheck.Text = "Reload Admin Keys";
            BooksListControl.ItemsSource = null;
            revealState = !revealState;
            return;
        }       
    }

    private void BtnLogin_Clicked(object sender, EventArgs e)
    {
        //shifty debug
        btnLogin.Text = "click received...";

        string user = entUsername.Text;
        string pass = entPassword.Text;
        string[] users = new string[result.Members.Length];
        string[] passes = new string[result.Members.Length];
        for (int i = 0; i < result.Members.Length; i++)
        {
            users[i] = result.Members[i].Usr;
            users[i] = result.Members[i].Pass;
        }

        if (user == string.Empty || pass == string.Empty)
        {
            InputError($"User: {user}\nPass: {pass}\n Nothing was entered in one of the text fields");
        }
        else
        {
            switch (user)
            {
                case "gruff":
                    case "kieran":
                        case "zara":
                        {
                            NextPage();
                            break;
                        }
                default:
                    InputError($"User: {user}\nPass: {pass}\n Not a correct user and/or password");
                    break;
            }
        }
    }
    private void InputError(string v)
    {
         Navigation.PushModalAsync(new InfoModal(v));
    }
    private void NextPage()
    {
        btnLogin.Text = "At NextPage Method caledl";
        //so after a number of attempts to show a modal or next page 
        //some success with modal above, but possibly hangs after... i think
        //no success with content page change: the start for tomrorrow :/
        Navigation.PushAsync((new ClientMainPage()));
    }
}

所以重申一下,问题在于通过单击按钮在一页与另一页之间导航,这似乎正在触发并且验证的模式替代方案按预期工作,但是当找到正确的详细信息时,它不会' 按预期触发新页面 :( 我知道我错过了那个 obvs,但我对这个环境还很陌生,所以很高兴知道我绊倒的是什么,这样我就可以把它放到愚蠢的陷阱框中。 再次非常感谢任何读到这里并能提供帮助的人。 (以下是该项目的副本,以防我所说的内容在没有正确查看的情况下不容易破译)

SKT Project @ GoogleDrive

看来我是个彻头彻尾的白痴,并没有更改 App.xaml.cs 以在 MainPage()

的应用程序入口上调用导航页面

我真是个笨蛋,但我猜这是因为没有规律的休息而迷失了方向。 我必须感谢@ToolMakerSteve 对 APp.xaml 的点头,因为当我到达那里时,我注意到它不在导航页面设置中

是...

MainPage = new MainPage();

现在...

MainPage = new NavigationPage( new MainPage());

这解决了这个问题 [还有我的理智,感谢您作为音板 Whosebug 和贡献者在那里] 当然,它表明我的验证很糟糕,因为任何密码和任何用户名组合现在都可以进入下一个视图,哈哈,所以现在需要正确控制它:)