简体   繁体   中英

Xamarin.Form MasterDetailPage fix DetailPage location

How i can remove black line on the top of DetailPage in Xamarim.Forms. I've created sample MasterDetail Page and got line on top. How I can fix it?

I didn't found any padding setting on DetailPage.

屏幕截图1

屏幕截图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() { }
}

You are embedding a NavigationPage into another NavigationPage .

In your public App() constructor instead of:

MainPage = new NavigationPage(new RootPage());

Do this:

MainPage = new RootPage();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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