[英]Set navigation side menu background image in Xamarin Forms
In Xamarin forms I want to use an image ( png file ) I created as background for a side "hamburger" menu. 在Xamarin表单中,我想使用作为背景创建的图像(png文件)作为侧面“汉堡”菜单。 For example, here is some menu:
例如,这是一些菜单:
Two questions: 两个问题:
1) What's the best image size to use for the menu background 1)菜单背景使用的最佳图像尺寸是多少
2) How do I put a ListView that contains my menu options on top of the background image ? 2)如何将包含菜单选项的ListView放在背景图像上方?
I tried using the grid but wasn't successful at stacking them. 我尝试使用网格,但未能成功堆叠它们。 Code below is a quick summary of how the MasterDetailPage is structured.
下面的代码是MasterDetailPage的结构的快速摘要。
//Menu
<MasterDetailPage.Master>
<ContentPage>
<ContentPpage.Content>
<AbsoluteLayout> //Also tried FlexLayout and RelativeLayout
<Image Source="blah" Aspect="Fill"/>
<Grid>
<ListView/>
</Grid>
</AbsoluteLayout>
</ContentPpage.Content>
<ContentPage>
</MasterDetailPage.Master>
//Page content
<MasterDetailPage.Detail>
<ContentPage>
///Page content
</ContentPage>
</MasterDetailPage.Detail>
The goal is to get the side menu looking something like this: 目的是使副菜单看起来像这样:
I just tried one sample solution. 我只是尝试了一种示例解决方案。 This is my master page :
这是我的主页:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="using:MasterDetailPageNavigation"
x:Class="MasterDetailPageNavigation.MasterPage"
Padding="0,40,0,0"
Icon="hamburger.png"
Title="Personal Organiser">
<Grid>
<Image Source="Default-Portrait.png" Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
<StackLayout Margin="0,20,0,0">
<ListView x:Name="listView" x:FieldModifier="public" BackgroundColor="Transparent">
<ListView.ItemsSource>
<x:Array Type="{x:Type local:MasterPageItem}">
<local:MasterPageItem Title="Contacts" IconSource="contacts.png" TargetType="{x:Type local:ContactsPage}" />
<local:MasterPageItem Title="TodoList" IconSource="todo.png" TargetType="{x:Type local:TodoListPage}" />
<local:MasterPageItem Title="Reminders" IconSource="reminders.png" TargetType="{x:Type local:ReminderPage}" />
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="5,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding IconSource}" />
<Label Grid.Column="1" Text="{Binding Title}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</Grid>
</ContentPage>
There is a trick to have Grid as a parent. 有一个技巧可以让Grid作为父项。 If you put 2 controls in same Cell it will overlap.
如果将2个控件放在同一单元格中,它将重叠。 Here my background image "Default-Portrait" will get overlapped by my StackLayout (listview) which has Background Color set as "Transparent".
在这里,我的背景图像“ Default-Portrait”将与我的StackLayout(列表视图)重叠,其背景色设置为“透明”。
For the Size of the Image, I would use multiple Size and put those images in the appropriate drawable-hdpi directory in android and iOS assets. 对于图像的大小,我将使用多个大小并将这些图像放入android和iOS资产中的相应drawable-hdpi目录中。
Let me know if you need any more clarifications. 让我知道是否需要更多说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.