public class MasterPageItem { public string Title { get; set; } public string IconSource { get; set; } public Type TargetType { get; set; } }
<?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="PurpleHeart.MasterPage" Title="Menu" Padding="0,40,0,0"> <ContentPage.Content> <StackLayout VerticalOptions="FillAndExpand"> <ListView x:Name="MyListView" VerticalOptions="FillAndExpand" SeparatorVisibility="None"> <ListView.ItemTemplate> <DataTemplate> <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" /> </DataTemplate> </ListView.ItemTemplate> </ListView> </StackLayout> </ContentPage.Content> </ContentPage>
.cs
public partial class MasterPage : ContentPage { public ListView ListView { get { return MyListView; } } public MasterPage () { InitializeComponent (); var masterPageItems = new List<MasterPageItem> { new MasterPageItem { Title = "Shops", IconSource = "shop.png", TargetType = typeof (MyShops) }, new MasterPageItem { Title = "Settings", IconSource = "settings.png", TargetType = typeof (SettingsPage) }, new MasterPageItem { Title = "My Orders", IconSource = "my_order.png", TargetType = typeof (MyOrderPage) }, new MasterPageItem { Title = "Logout", IconSource = "home1.png", TargetType = typeof (Login) } }; MyListView.ItemsSource = masterPageItems; } }