简体   繁体   English

如何从Xamarin.forms中的按钮单击从一个页面移动到另一个页面

[英]how to move from one page to another from button click in Xamarin.forms

I just wanted to know that how to move from one Content Page to another Content Page..Please review the elseif() code ..What I have to write in that block so that I could move to another Content Page(named as MainView.cs).. 我只是想知道如何从一个内容页面移动到另一个内容页面。请查看elseif()代码。我必须在该块中编写,以便我可以移动到另一个内容页面(命名为MainView)。 CS)..

 button.Clicked += (sender, e) =>
        {
            if (String.IsNullOrEmpty(username.Text) || String.IsNullOrEmpty(password.Text))
            {
                DisplayAlert("Oops!!Validation Error", "Username and Password are required", "Re-try");
            }

            else if (username.Text == "kanak" && password.Text == "1234")
            {
               // your code here                   
            }
            else
            {
                DisplayAlert("Failed", "Invalid User", "Login Again");
            }
        };

Any help is appreciated.. 任何帮助表示赞赏..

First wrap you main contentPage in a NavigationPage . 首先将您的主要contentPage包装在NavigationPage From there you will use Navigation by PushAsync(new SomeNewPage()); 从那里你将使用PushAsync(new SomeNewPage());导航PushAsync(new SomeNewPage()); .

In your case it should be.... 在你的情况下它应该....

 else if (username.Text == "kanak" && password.Text == "1234")
            {
                Navigation.PushAsync(new <App-Root-name>.<folder-name>.<Class-Name>());
            }

Sample Example (Taken From GitHub)... 示例示例 (取自GitHub)...

using System;
using Xamarin.Forms;

namespace FormsGallery
{
    class TableViewMenuDemoPage : ContentPage
    {
        public TableViewMenuDemoPage()
        {
            Label header = new Label
            {
                Text = "TableView for a menu",
                Font = Font.SystemFontOfSize(30, FontAttributes.Bold),
                HorizontalOptions = LayoutOptions.Center
            };
            TableView tableView = new TableView
                {
                    Intent = TableIntent.Menu,
                    Root = new TableRoot
                    {
                        new TableSection("Views for Presentation")
                        {
                            new TextCell
                            {
                                Text = "Label",
                                Command = new Command(async () => 
                                    await Navigation.PushAsync(new LabelDemoPage()))
                            },
                            new TextCell
                            {
                                Text = "Image",
                                Command = new Command(async () => 
                                    await Navigation.PushAsync(new ImageDemoPage()))
                            },
                            new TextCell
                            {
                                Text = "BoxView",
                                Command = new Command(async () => 
                                    await Navigation.PushAsync(new BoxViewDemoPage()))
                            },
                            new TextCell
                            {
                                Text = "WebView",
                                Command = new Command(async () => 
                                    await Navigation.PushAsync(new WebViewDemoPage()))
                            },
                        }
                    }
                };

            // Build the page.
            this.Content = new StackLayout
            {
                Children = 
                {
                    header,
                    tableView
                }
            };
        }
    }
}
else if (username.Text == "kanak" && password.Text == "1234")
        {
            Navigation.PushAsync(new <App-Root-name>.<folder-name>.<Class-Name>());
        }

In the code . 在代码中。 What is meant by <App-Root-name> and <folder-name> and <Class-Name> ??? <App-Root-name><folder-name>以及<Class-Name>是什么意思?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Xamarin.Forms中将字符串从一页传递到另一页 - Passing a string from one page to another in Xamarin.Forms 在 xamarin.forms 中将标签从一页添加到另一页的列表视图 - Adding labels to a listview from one page to another in xamarin.forms 如何在Xamarin.Forms中单击按钮时从地图上删除折线 - How to remove polyline from the map on button click in Xamarin.Forms 如何在Xamarin.Forms中将参数从一个页面传递到另一个页面? - How to pass a parameter from one Page to another Page in Xamarin.Forms? Xamarin.forms 从页面上的按钮单击导航到 shell 中的不同页面 - Xamarin.forms navigate to different page in shell from button click on page hybridWebView 页面从 Xamarin.Forms 中的 Javascript 打开另一个 ContentPage - hybridWebView page open another ContentPage from Javascript in Xamarin.Forms Xamarin.Forms Prism-使用导航服务从一个详细信息页面导航到另一个 - Xamarin.Forms Prism - Using navigation service to navigate from one detail page to another 如何使用Xamarin.Forms通过单击按钮打开Goog​​le Play图书? - How to open Google play books from a button click using Xamarin.Forms? 在使用 Xamarin.Essentials 抖动检测事件时,未在 Xamarin.Forms 中从一页导航到另一页 - Not navigating from one page to another page in Xamarin.Forms while using using Xamarin.Essentials shake detect event 如何在 xamarin.forms 中的 viewcell 中设置按钮以从内容页面 viewmodel 调用命令? - How do I set a button in viewcell in xamarin.forms to call a command from the content page viewmodel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM