Navigation DropDown dengan Xamarin Forms

Pada tutorial berikut ini saya akan membahas bagaimana cara menggunakan Navigation DropDown pada Xamarin Forms.

1. Tambahkan halaman xaml DropdownMenu.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage Title="Dropdown menggunakan Toolbar" xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Bab4.DropdownMenu">
  <ContentPage.ToolbarItems>
    <ToolbarItem Text="Home" Order="Secondary" Clicked="Navigate" CommandParameter="NavigationPage1" />
    <ToolbarItem Text="Second" Order="Secondary" Clicked="Navigate" CommandParameter="NavigationPage2" />
  </ContentPage.ToolbarItems>
  <ContentPage.Content>
  </ContentPage.Content>
</ContentPage>

2. Tambahkan kode berikut pada file DropdownMenu.xaml.cs:

    public partial class DropdownMenu : ContentPage
    {
        public DropdownMenu()
        {
            InitializeComponent();
        }

        protected async void Navigate(object sender, EventArgs args)
        {

            string type = (string)((ToolbarItem)sender).CommandParameter;
            Type pageType = Type.GetType("Bab4." + type + ", Bab4");
            Page page = (Page)Activator.CreateInstance(pageType);
            await this.Navigation.PushAsync(page);
        }
    }

3. Jalankan program untuk melihat hasilnya. Tampilan menu dropdown yang dibuat dapat dilihat pada gambar berikut.

image

Advertisements

About Erick Kurniawan

IT Trainer, Consultant, & Microsoft Azure MVP Actual Training (http://actual-training.com)
This entry was posted in Cross Platform Mobile Development, Xamarin Forms and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s