【问题标题】:Xamarin Form Master Detail Page not displayingXamarin 表单主详细信息页面未显示
【发布时间】:2014-09-26 15:31:37
【问题描述】:

我正在使用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
                },
            }
        };
    }
}

【问题讨论】:

  • 您应该能够滑动以使大师出现。您还可以将 Title 和 Icon 属性分配给 Master ContentPage,这应该会在 Detail 上显示一个按钮,您可以单击该按钮以显示 Master。
  • 除此之外:title 属性对于 Master 的 ContentPage 来说是必需的
  • 我已经发布了 Xamarin.Forms 主从页面 here 的最小工作示例。

标签: c# android ios xamarin xamarin.forms


【解决方案1】:

请尝试以下代码:

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

【讨论】:

    猜你喜欢
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 2018-06-02
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2019-07-19
    相关资源
    最近更新 更多