简体   繁体   English

Xamarin表格主细节页面不显示

[英]Xamarin Form Master Detail Page not displaying

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. 我正在使用Xamarin form with MasterDetailPage base classXamarin form with MasterDetailPage base class但我无法获取母版页。详细信息页面即将出现但master菜单未显示..请检查下面的代码。 Do i need to specify any other method to call the master or anything wrong which i am doing in the below code 我需要指定任何其他方法来调用master或我在下面的代码中做的任何错误

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
                },
            }
        };
    }
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM