c# - Xamarin 表单主详细信息页面未显示

标签 c# android ios xamarin xamarin.forms

我正在使用带有 MasterDetailPage 基类的 Xamarin 表单 但是我无法获取母版页。详细信息页面即将出现,但 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
                },
            }
        };
    }
}

最佳答案

请尝试以下代码:

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

关于c# - Xamarin 表单主详细信息页面未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25113939/

相关文章:

android - Ice Cream Sandwich 中 HttpURLConnection 的 FileNotFoundException

java - 调用一个类并显示结果

ios - 在 Swift 中使用 if 语句?

c# - 单击 winforms (C#) 中的按钮后,如何将 `SendKeys` 发送到最后一个事件输入文本框?

C# 将多个数组合并为一个数组

c# - 如何让 .NET 4 应用程序的主窗体出现在最前面?

c# - 带对象的枚举或类似字典的枚举

java - 作为一个对 Java 有基本了解的学生,我可以转向 Android 吗?

iphone - 删除 NSDocumentDirectory 中的图像

ios - Core Data 未将 NSManagedObject 实例作为应用程序委托(delegate)的属性触发故障