Articles in this section
Category / Section

How to Navigate to a page in SfNavigationDrawer in Xamarin.Forms application?

2 mins read

Syncfusion NavigationDrawer provides the feature of navigation from one page to another page.

 

To navigate from one page to another follow the below given procedure.

 

Step 1: Create the navigation drawer with all necessary assemblies.

Step 2: Enter the code in App.xaml.cs page as such. And also use the below given codes in the respective pages.

 

The below code illustrates how to navigate to another page.

Code behind code for main page:

namespace DrawerExample
{
public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        SfNavigationDrawer navigationDrawer = new SfNavigationDrawer();
        Title = "Navigation Drawer";
        //Drawer content.
        Grid drawercontentlayout = new Grid();
        Label drawer = new Label();
        drawer.Text = "Drawer Content";
        drawer.FontSize = 14;
        drawer.TextColor = Color.Black;
        drawer.HorizontalTextAlignment = TextAlignment.Center;
        drawer.VerticalTextAlignment = TextAlignment.Center;
        drawercontentlayout.Children.Add(drawer);
        navigationDrawer.DrawerContentView = drawercontentlayout;
 
        //Header 
        Grid headerLayout = new Grid();
        headerLayout.BackgroundColor = Color.FromHex("#1aa1d6");
        Label header = new Label();
        header.Text = "Header View";
        header.FontSize = 14;
        header.TextColor = Color.White;
        header.HorizontalTextAlignment = TextAlignment.Center;
        header.VerticalTextAlignment = TextAlignment.Center;
        header.BackgroundColor = Color.FromHex("#1aa1d6");
        headerLayout.Children.Add(header);
        navigationDrawer.DrawerHeaderView = headerLayout;
 
        //Footer 
        Grid footerlayout = new Grid();
        footerlayout.BackgroundColor = Color.FromHex("#1aa1d6");
        Label footer = new Label();
        footer.Text = "Footer View";
        footer.FontSize = 14;
        footer.TextColor = Color.White;
        footer.HorizontalTextAlignment = TextAlignment.Center;
        footer.VerticalTextAlignment = TextAlignment.Center;
        footer.BackgroundColor = Color.FromHex("#1aa1d6");
        footerlayout.Children.Add(footer);
        navigationDrawer.DrawerFooterView = footerlayout;
 
        navigationDrawer.Position = Position.Left;
        navigationDrawer.Transition = Transition.SlideOnTop;
        navigationDrawer.DrawerWidth = 200;
        navigationDrawer.DrawerHeaderHeight = 50;
        navigationDrawer.DrawerFooterHeight = 50;
 
        StackLayout stack = new StackLayout();
        Button bt = new Button();
        bt.Text = "Next_Page";
        bt.VerticalOptions = LayoutOptions.CenterAndExpand;
        bt.HorizontalOptions = LayoutOptions.CenterAndExpand;
        bt.Clicked += Bt_Clicked;
        stack.Children.Add(bt);
        navigationDrawer.ContentView = stack;
 
        this.Content = navigationDrawer;
 
    }
 
    async void Bt_Clicked(object sender, System.EventArgs e)
    {
        await Navigation.PushAsync(new NavigationPage2());
    }
}
}
 

Navigation page XAML code:

<!--Navigation page content--> 
<StackLayout>        
  <Label Text="Navigated Page" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" />       
</StackLayout>   

 

In App.xaml.cs page. Use the following code:

public App()
{
InitializeComponent();
 
MainPage = new NavigationPage(new DrawerExample.MainPage());
}

 

Main page with Opened:

Main page with Opened in SfNavigationDrawer

Navigated page:

Navigated page in SfNavigationDrawer

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied