不显示Xamarin表单母版详细信息页

本文关键字:详细信息 表单 显示 Xamarin | 更新日期: 2023-09-27 18:16:39

我正在使用Xamarin form with MasterDetailPage base class,但我无法获得母版页。详细页面即将到来,但master菜单没有显示…请检查下面的代码。我是否需要指定任何其他方法来调用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
                },
            }
        };
    }
}

不显示Xamarin表单母版详细信息页

请尝试以下代码:

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