Search code examples
xamarin.formsmenuitemmaster-detail

What is the best way to create the MasterDetailPage menu items in Xamarin.Forms


I'm using a MasterDetailPage in my Xamarin.Forms application.

To creat the menu items, I use buttons

<MasterDetailPage.Master>
    <ContentPage Title="Menu">
        <StackLayout Orientation="Vertical">
            <Button Text="Club-House" Command="{Binding ClubHouseCommand}" />
            <Button Text="Parcours" />
            <BoxView VerticalOptions="CenterAndExpand" />
            <Button Text="A propos" Command="{Binding AProposCommand}" VerticalOptions="End" />
        </StackLayout>
    </ContentPage>
</MasterDetailPage.Master>

Is there a better way to do it ? I was thinking about something more menuish like MenuItem or else.

Thanks


Solution

  • There is nothing standard for implementing a menu in the Master page.

    You can use

    1. ListView
    2. StackLayout
    3. Grid

    Or a combination. StackLayout and ListView will most likely be your best options. Personally I go for a StackLayout because it's quicker to code and render than a ListView, which may come with more issues than advantages. However if I have a large menu (which I try to avoid), ListView may be quicker to code. But ListViews are generally meant for dynamically loaded data, not static.

    As for the elements, the most common will be

    1. Button
    2. Label

    While buttons are designed for clicking, sometimes I move to label's if I don't want to have to undo all the default styling, and use the TapGestureRecognizer.

    You can create a new User Control for a menu item, to avoid code replication.

    All up, there is no standard. Make it easy to code and understand, and quick to render. How you do that, depends on your requirements.