4

I am using the Xamarin form with MasterDetailPage base class But I am not able to get the master page .. Detail page is coming but master menu is not displaying .. Please check the code below. Do i need to specify any other method to call the master or anything wrong which i am doing in the below code

public class HomeView: MasterDetailPage
{
    public   HomeView()
    {
        Label header = new Label
        {    
            Text = "MENU",
            Font = Font.BoldSystemFontOfSize(20),HorizontalOptions = LayoutOptions.Center
        };

        Label header1 = new Label
        {
            Text = "MENU1",
            Font = Font.BoldSystemFontOfSize(20),
            HorizontalOptions = LayoutOptions.Center
        };

        // create an array of the Page names
        string[] myPageNames = { "Main", "Page 2", "Page 3"};

        // Create ListView for the Master page.
        ListView listView = new ListView
        {
            ItemsSource = myPageNames,
        };

        ListView listView1 = new ListView
        {
            ItemsSource = myPageNames,
        };


        this.Master = new ContentPage
        {
            Content = new StackLayout
            {
                Children = 
                {
                    header, 
                    listView
                }
            }
        };

        // Set up the Detail, i.e the Home or Main page.
        Label myHomeHeader = new Label
        {
            Text = "Home Page",
            HorizontalOptions = LayoutOptions.Center
        };

        string[] homePageItems = { "Alpha", "Beta", "Gamma" };
        ListView myHomeView = new ListView 
        {
            ItemsSource = homePageItems,
        };

        this.Detail = new ContentPage
        {
            Content = new StackLayout
            {
                Children = 
                {
                    header1, 
                    listView1
                },
            }
        };
    }
}
bkardol
  • 1,258
  • 1
  • 20
  • 32
user3226440
  • 559
  • 1
  • 8
  • 23
  • You should be able to swipe to make the Master appear. You can also assign a Title and Icon property to the Master ContentPage, this should display a button on the Detail that you can click to display the Master. – Jason Aug 04 '14 at 10:46
  • In addition to that: the title property is **required** for the Master's ContentPage. – bkardol Aug 04 '14 at 10:56
  • I've posted a minimal working example for Xamarin.Forms master-detail pages [here](http://stackoverflow.com/q/24700112/3419103). – Falko Aug 08 '14 at 16:59

1 Answers1

1

Please Try the following Code:

public class HomeView: MasterDetailPage
{
    public   HomeView()
    {
        Label header = new Label
        {    
            Text = "MENU",
            Font = Font.BoldSystemFontOfSize(20),
            HorizontalOptions = LayoutOptions.Center
        };

        Label header1 = new Label
        {
            Text = "MENU1",
            Font = Font.BoldSystemFontOfSize(20),
            HorizontalOptions = LayoutOptions.Center
        };

        // create an array of the Page names
        string[] myPageNames = { "Main", "Page 2", "Page 3"};

        // Create ListView for the Master page.
        ListView listView = new ListView
        {
            ItemsSource = myPageNames,
        };

        ListView listView1 = new ListView
        {
            ItemsSource = myPageNames,
        };

        this.Master = new ContentPage
        {
            Content = new StackLayout
            {
                Children = 
                {
                    header, 
                    listView
                }
                }
        };

        // Set up the Detail, i.e the Home or Main page.
        Label myHomeHeader = new Label
        {
            Text = "Home Page",
            HorizontalOptions = LayoutOptions.Center
        };

        string[] homePageItems = { "Alpha", "Beta", "Gamma" };
        ListView myHomeView = new ListView 
        {
            ItemsSource = homePageItems,
        };

        this.Detail = new NavigationPage(new ContentPage
        {
            Content = new StackLayout
            {
                Children = 
                {
                    header1, 
                    myHomeView
                },
            }
        });
    }
}
Ram Ch. Bachkheti
  • 2,609
  • 2
  • 17
  • 14