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

发布于 2025-01-29 20:57:41 字数 5967 浏览 4 评论 0原文

嗨,感谢您提前阅读... 我有一个旨在为皮划艇公司提供客户端预订系统的项目,并创建了初始登录页面,该页面适用于验证方面的所有意图和目的,但是当我单击登录按钮时,它不会转移到下一个内容页面[视图]。 我附上了一个视频链接,显示了这个问题,但是我很感谢您在整夜都在发现我错过了什么愚蠢的事情时,并认为我对此有些看不见明显的!? 导航问题屏幕录制

    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()));
}

以下是整个代码表,以确保更好的清晰度,但是上面的代码是触发和生产我的我的代码表我认为可疑的结果:(

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()));
    }
}

要重申,问题是在单击按钮时在一个页面之间导航到另一页之间,这似乎是在触发,而验证的模态替代方案是按预期工作的,但是当找到正确的详细信息时,不会像预期的那样发射新页面 :(我知道这是我所缺少的,但是我对这个环境来说是个新手,所以很高兴知道我绊倒了什么,所以我可以将其放入傻瓜盒子中。 非常感谢任何阅读本文并可以提供帮助的人。 (下面是该项目的副本,以防我所说的话,如果没有适当的外观就不太容易解密)

skt project @ googledrive

Hi and thanks for reading in advance...
I have a project designed to deliver a client booking system for a kayak company and have created the initial login page, which works for all intent and purposes with respect to validation but when I click the login button [and the details seem to be validated, it doesn't shift over to the next content page [view].
I've attached a video link showing the issue in practice, but I would appreciate some help in discovering what stupid thing I've missed as I've been at it all night and today and think I've gone a bit blind to the obvious!?
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(
quot;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(
quot;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()));
}

Below is the whole code sheet for better clarity, but it's the code above that's fired and producing my questionable outcome I think :(

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 = 
quot;{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(
quot;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(
quot;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()));
    }
}

So to reiterate, the issue is around navigating between one page to another on a button click, that appears to be firing and the modal alternative for validation is working as expected, but when the correct details are found, it doesn't fire the new page as expected
:( I know its something I'm missing that obvs, but I am fairly new to this environment so it would be great to know what it is that I'm stumbling on so I can put it into the silly gotchas box.
Thanks so much again to anyone who read this far and can help.
(Below is a copy of the project in case what I've said is just not as easy to decipher without a proper look)

SKT Project @ GoogleDrive

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末 2025-02-05 20:57:42

因此,看来我是一个完整的白痴,也没有更改teh app.xaml.cs来调用app entry for mainpage()

我真clut脚的 导航页面失去了一切。
我必须感谢@toolmakersteve对app.xaml的点头,因为当我到达那里时,我注意到这不是在导航页面

...

MainPage = new MainPage();

MainPage = new NavigationPage( new MainPage());

设置 作为音板堆叠流和贡献者在那里]
当然,它揭示了我的验证很烂,因为任何密码和任何用户名组合现在都可以到达下一个视图,因此现在需要正确控制它:)

So it looks like I was a complete idiot and did NOT change the teh App.xaml.cs to invoke a navigation page on app entry for MainPage()

I'm such a clutz, but guess its due to not taking regular breaks and getting lost in it all doh.
I have to thank @ToolMakerSteve for his nod to APp.xaml, as when I got there i noticed it wasnt in the Navigation Page setup

was...

MainPage = new MainPage();

now...

MainPage = new NavigationPage( new MainPage());

THIS SOLVED HAS THIS ISSUE [and somewhat my sanity, thank you for being there as a soundboard Stackoverflow and contributors]
Of course it revealed my validation sucks as any password and any user name combo can get to next view now lol so now need to correctly control that :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文