Reputation: 3748
I have this code in Xaml :
<Button Text="Click Me" Clicked="OnButtonClicked" />
And this code in code-behind :
void OnButtonClicked(object sender, EventArgs args)
{
}
How can I navigate a page in this method ?
Upvotes: 0
Views: 4888
Reputation: 2256
First, make sure that your app is based on a NavigationPage
to enable navigation in Xamarin.Forms. For this, set the MainPage
property of your App.cs
to a NaviationPage
instance.
public App()
{
MainPage = new NavigationPage(new YourStartPage());
}
Now add a second Forms Xaml Page
or Forms ContentPage
to your project, that you can navigate to from your start page. Make sure, your OnButtonClicked
handler is declared as async
(like in the sample below) and navigate like this:
async void OnButtonClicked(object sender, EventArgs args)
{
await Navigation.PushAsync(new Page2());
}
Upvotes: 5