Xamarin.Form MasterDetailPage修复DetailPage位置

时间:2016-07-14 17:58:06

标签: c# xamarin xamarin.forms

如何删除Xamarim.Forms中DetailPage顶部的黑线。 我已经创建了样本MasterDetail页面并且排在最前面。 我怎么解决它?

我在DetailPage上找不到任何填充设置。

screenshot 1

screenshot 2

RootPage.cs

   public class RootPage : MasterDetailPage
{
    private readonly string _content;

    public RootPage(string content)
    {
        NavigationPage.SetHasNavigationBar(this, false);
        //       _content = content;
        var menuPage = new MenuPage();

        menuPage.Menu.ItemSelected += (sender, e) => NavigateTo(e.SelectedItem as MenuItem);

        Master = menuPage;

        Detail = new NavigationPage(new ContractsPage());
        //   InitViews();
    }

    void NavigateTo(MenuItem menu)
    {
        Page displayPage = (Page)Activator.CreateInstance(menu.TargetType);

        Detail = new NavigationPage(displayPage);

        IsPresented = false;
    }   
}

MenuPage.cs

   public class MenuPage : ContentPage
{
    public ListView Menu { get; set; }

    public MenuPage()
    {
        Icon = "settings.png";
        Title = "menu"; // The Title property must be set.
        BackgroundColor = Color.FromHex("333333");

        Menu = new MenuListView();

        var menuLabel = new ContentView
        {
            Padding = new Thickness(10, 36, 0, 5),
            Content = new Label
            {
                TextColor = Color.FromHex("AAAAAA"),
                Text = "MENU",
            }
        };

        var layout = new StackLayout
        {
            Spacing = 0,
            VerticalOptions = LayoutOptions.FillAndExpand
        };
        layout.Children.Add(menuLabel);
        layout.Children.Add(Menu);

        Content = layout;
    }



}


public class MenuItem
{
    public string Title { get; set; }

    public string IconSource { get; set; }

    public Type TargetType { get; set; }
}


public class MenuListView : ListView
{
    public MenuListView()
    {
        List<MenuItem> data = new MenuListData();

        ItemsSource = data;
        VerticalOptions = LayoutOptions.FillAndExpand;
        BackgroundColor = Color.Green;

        var cell = new DataTemplate(typeof(ImageCell));
        cell.SetBinding(TextCell.TextProperty, "Title");
        cell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");

        ItemTemplate = cell;
    }
}

public class MenuListData : List<MenuItem>
{
    public MenuListData()
    {
        this.Add(new MenuItem()
        {
            Title = "Contracts",
            IconSource = "contracts.png",
            TargetType = typeof(ContractsPage)
        });

        this.Add(new MenuItem()
        {
            Title = "Leads",
            IconSource = "Lead.png",
            TargetType = typeof(LeadsPage)
        });

        this.Add(new MenuItem()
        {
            Title = "Accounts",
            IconSource = "Accounts.png",
            TargetType = typeof(AccountsPage)
        });

        this.Add(new MenuItem()
        {
            Title = "Opportunities",
            IconSource = "Opportunity.png",
            TargetType = typeof(OpportunitiesPage)
        });
    }
}



public class ContractsPage : ContentPage
{
    public ContractsPage()
    {
        Title = "test";
        this.Padding=new Thickness(0,0,0,0);
        NavigationPage.SetTitleIcon(this, "icon.png");

    }
}

public class LeadsPage : ContentPage
{
    public LeadsPage() { }
}

public class AccountsPage : ContentPage
{
    public AccountsPage() { }
}

public class OpportunitiesPage : ContentPage
{
    public OpportunitiesPage() { }
}

1 个答案:

答案 0 :(得分:0)

您正在将NavigationPage嵌入另一个NavigationPage

public App()构造函数中,而不是:

MainPage = new NavigationPage(new RootPage());

这样做:

MainPage = new RootPage();