[英]Xamarin forms - Menu icon on ios
I have this MasterDetailPage
. 我有这个
MasterDetailPage
。
On UWP and Android the upper left icon of the menu is showed correctly, but on iOS appears the label "Menu". 在UWP和Android上,菜单的左上图标正确显示,但在iOS上显示标签“菜单”。
I have an image "Hamburger" inside the xcassets
, and I would like to use it. 我在
xcassets
内有一个“汉堡包”图像,我想使用它。
How can I make this works? 我该如何运作?
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:Menu_TEST.Views"
x:Class="Menu_TEST.Views.MainPage">
<MasterDetailPage.Master>
<views:MenuPage />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="Hamburger"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:ItemsPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
I have an image "Hamburger" inside the xcassets, and I would like to use it.
我在xcassets中有一个“汉堡包”图像,我想使用它。
If want to get image from xcassets
,you can refer to this discussion .However this maybe can not work here in MasterDetailPage.Master
.So suggest that better use the image from Resources folder. 如果要从
xcassets
获取图像,可以参考此讨论。但是,在MasterDetailPage.Master
这可能无法正常工作。因此建议更好地使用Resources文件夹中的图像。
<MasterDetailPage.Master>
<views:MenuPage />
</MasterDetailPage.Master>
From your code , MenuPage
is setted to the MasterDetailPage.Master
property. 在您的代码中,
MenuPage
被设置为MasterDetailPage.Master
属性。 If want to set icon to the upper left,you need to set in MenuPage.xaml
as follow. 如果要在左上方设置图标,则需要在
MenuPage.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="AppMasterDetail.Views.MenuPage"
Title="Menu"
Icon="hamburger.png"> //Here set icon ,image from 'Resources' folder
<StackLayout VerticalOptions="FillAndExpand">
<ListView x:Name="ListViewMenu"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Label Text="{Binding Title}" FontSize="20"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
If not have this hamburger.png
in project, you also can set title like CGPA6.4 said that. 如果项目中没有此
hamburger.png
,则还可以设置标题,例如CGPA6.4这样。
<?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="AppMasterDetail.Views.MenuPage"
Title="☰"> //Here change 'Menu' to '☰'
...
</ContentPage>
Here is a official document with sample , you can refer to. 这是带有样本 的正式文档 ,您可以参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.