如何在xamarin.Forms(iOS)的MasterDetailPage中添加humburger图标

时间:2017-06-22 09:19:59

标签: xamarin.ios navigation xamarin.forms navigation-drawer

我是Xamarin.Forms的新手。我正在为iOS和Android创建NavigationPage。所有的事情都很好。请看下面的ScreenShot。

在Android中

看起来像

enter image description here

但在iOS中显示效果不佳

enter image description here

代码:

MasterPage.xaml

<?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="DroidDrawer.MasterPage" Padding="0,0,0,0" Title="Menu" Icon="humburger">
    <ContentPage.Content>
        <StackLayout VerticalOptions="FillAndExpand" Orientation="Vertical" Padding="0,20,0,0" BackgroundColor="#004F80">
            <ListView x:Name="listView" VerticalOptions="FillAndExpand" SeparatorVisibility="None" BackgroundColor="#0072BA">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal">
                                <Image Source="{Binding IconSource}" HeightRequest="24" WidthRequest="24" VerticalOptions="Center" Grid.Column="0" Margin="12,10,0,10" />
                                <Label Text="{Binding Title}" Style="{DynamicResource LabelStyle}" VerticalOptions="Center" HeightRequest="24" TextColor="White" Grid.Column="1" Margin="10,13,0,10" />
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

MasterPage.xaml.cs

using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace DroidDrawer
{
    public partial class MasterPage : ContentPage
    {
        public ListView ListView { get { return listView; } }
        public MasterPage()
        {
            InitializeComponent();

            var masterPageItem = new List<MasterPageItem>();
            masterPageItem.Add(new MasterPageItem
            {
                Title = "Home",
                IconSource = "nav_home.png",
                TargetType = typeof(HomePage)
            });
            masterPageItem.Add(new MasterPageItem
            {
                Title = "CSS",
                IconSource = "nav_appointment.png",
                TargetType = typeof(CssPage)
            });
            masterPageItem.Add(new MasterPageItem
            {
                Title = "Javascript",
                IconSource = "nav_feedback.png",
                TargetType = typeof(JavascriptPage)
            });
            masterPageItem.Add(new MasterPageItem
            {
                Title = "Html",
                IconSource = "nav_financialinfo.png",
                TargetType = typeof(HtmlPage)
            });

            listView.ItemsSource = masterPageItem;

        }
    }
}

任何帮助都会得到赞赏。

1 个答案:

答案 0 :(得分:1)

6小时后,我得到的解决方案是我的问题是图标尺寸太大而不是它在屏幕上显示得那么大。设置30 * 30图像尺寸后,它解决了问题...