我是Xamarin.Forms的新手。我正在为iOS和Android创建NavigationPage。所有的事情都很好。请看下面的ScreenShot。
在Android中看起来像
但在iOS中显示效果不佳
代码:
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;
}
}
}
任何帮助都会得到赞赏。
答案 0 :(得分:1)
6小时后,我得到的解决方案是我的问题是图标尺寸太大而不是它在屏幕上显示得那么大。设置30 * 30图像尺寸后,它解决了问题...