Xamarin detail page

I use Xamarin form with MasterDetailPage base classBut I can not get the main page. A detailed page is coming, but the mastermenu is not displayed. Please check the code below. Do I need to specify any other method to call masteror something else that I do in the code below

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
                },
            }
        };
    }
}
+4
source share
1 answer

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
                },
            }
        });
    }
}
+1
source

All Articles