inside one tab i use this code and add button to navigate to another content page I make a tabbed page in Xamarin Forms And Inside tabbed page I take 4 content page for tab Inside those content page there are some button when I add click event on button. to navigate in another content page. button doesn't fire. Please provide some solution for this problem.
<NavigationPage Title="Home" IconImageSource="HomeGrey.png">
<x:Arguments >
<local:NewHomeScreen Title="Home" ></local:NewHomeScreen>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Pickup" IconImageSource="PickupGrey.png">
<x:Arguments>
<local:PickupPage ></local:PickupPage>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Setting" IconImageSource="settings.png">
<x:Arguments>
<local:NewSetting ></local:NewSetting>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Support" IconImageSource="SupportGrey.png">
<x:Arguments>
<local:SupportPage ></local:SupportPage>
</x:Arguments>
</NavigationPage>
If you want to switch to the next tab of the TabbedPage
on clicking button, you can try to use EventHandler
to achieve this.
I achieved this function,you can refer to the following code:
FirstPage.xaml.cs
public partial class FirstPage : ContentPage
{
public event EventHandler<string> ButtonClickedHandler;
public FirstPage ()
{
InitializeComponent ();
}
private void Button_Clicked(object sender, System.EventArgs e)
{
ButtonClickedHandler?.Invoke(this, "topage2");
}
}
FirstPage.xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedPageWithNavigationPage.FirstPage"
IconImageSource="test.png"
Title="Today">
<ContentPage.Content>
<StackLayout>
<Label Text="Today's appointments go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
<Button Text="navigate" Clicked="Button_Clicked"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
MainPage.xaml.cs
public partial class MainPage : TabbedPage
{
public MainPage ()
{
InitializeComponent ();
tabPage1.ButtonClickedHandler += delegate (object obj,string str) {
CurrentPage = tabPage2;
};
}
}
MainPage.xaml
<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
x:Class="TabbedPageWithNavigationPage.MainPage"
x:Name="tabbedPage"
>
<local:FirstPage x:Name="tabPage1" />
<NavigationPage Title="Schedule" IconImageSource="schedule.png" x:Name="tabPage2">
<x:Arguments>
<local:SecondPage />
</x:Arguments>
</NavigationPage>
<local:ThirdPage x:Name="tabPage3"/>
</TabbedPage>
Update:
I did a test using your code, but it threw error **System.InvalidCastException:** 'Specified cast is not valid.'
. Since the current page is a ContentPage
, so you cannot cast it to TabbedPage
.
If you want to navigate to another page instead of other tabs, you can try code:
Navigation.PushAsync (new DeliveryDetailPaidPage());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.