Header for ListView in MasterDetailSplitView

Hey guys,

I have a problem with the header/Navigationbar of the ListView, see the image below. I created a SplitView in Xamarin.Forms, but there is no Navigationbar over the SplitView on iOS (on Android it works fine). Can someone help me to create this in C#?

Here is my Master-Class:

`public class VisitorItemPage : ContentPage
{
public ListView listView;
private VisitorsItemDatabase _database;
private int selectedId;

    public VisitorItemPage (VisitorsItemDatabase database)
    {
        _database = database;

        Title = "Teilnehmer";

        var header = new Label {

            Text = "Text",
            Font = Font.SystemFontOfSize(20),

            HeightRequest = 40,
            XAlign = TextAlignment.Center

        };

        listView = new ListView {
            RowHeight = 40,
            ItemTemplate = new DataTemplate (typeof(VisitorItemCell))
        };

        var visitor = _database.GetVisitorItem ();
        listView.ItemsSource = visitor;

        listView.ItemSelected += (sender, e) => {
            if (e.SelectedItem == null) {
                return;
            }
            var visitorItem = (VisitorItem)e.SelectedItem;
            setSelectedId(visitorItem.ID);
            //DisplayAlert("Tapped", getSelectedId() + " Row was selected", "ok");
            var visitorDetailPage = new VisitorDetailPage (this, database);
            visitorDetailPage.BindingContext = visitorItem;
            ((ListView)sender).SelectedItem = null; 
            //Navigation.PushAsync (visitorDetailPage);
        };


        this.Content = new StackLayout {
            Children = {
                header,
                listView
            }
        };
    }

}`

Best Answer

  • TorbenKruseTorbenKruse DE ✭✭✭
    Accepted Answer

    You need to add Padding on iOS. Something like this:

    this.Content = new StackLayout
    {
        Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
        Children = 
        {
            header,
            listView
        }
    };
    

Answers

  • TorbenKruseTorbenKruse DEMember ✭✭✭
    Accepted Answer

    You need to add Padding on iOS. Something like this:

    this.Content = new StackLayout
    {
        Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
        Children = 
        {
            header,
            listView
        }
    };
    
Sign In or Register to comment.