我在exrin中使用MasterDetailPage 这是我的ViewContainer 公共类MainViewContainer:Exrin.Framework.ViewContainer,IMasterDetailContainer { 私人只读MasterDetailPage r_MasterPage;
public MainViewContainer(MenuStack i_MenuStack, MainStack i_MainStack)
: base(eContainer.Main.ToString())
{
r_MasterPage = new MasterDetailPage();
MasterDetailProxy masterProxy = new MasterDetailProxy(r_MasterPage);
NativeView = masterProxy.View;
Proxy = masterProxy;
DetailStack = i_MainStack;
MasterStack = i_MenuStack;
RegionMapping.Add(eRegions.Menu, ContainerType.Master);
RegionMapping.Add(eRegions.Main, ContainerType.Detail);
}
public IHolder MasterStack { get; set; }
public IHolder DetailStack { get; set; }
public IMasterDetailProxy Proxy { get; set; }
public bool IsPresented
{
get
{
return r_MasterPage.IsPresented;
}
set
{
r_MasterPage.IsPresented = value;
}
}
public void SetStack(ContainerType i_ContainerType, object i_Page)
{
switch (i_ContainerType)
{
case ContainerType.Detail:
r_MasterPage.Detail = i_Page as Page;
break;
case ContainerType.Master:
r_MasterPage.Master = i_Page as Page;
break;
}
}
}
这是我的IMasterDetailProxy 公共类MasterDetailProxy:IMasterDetailProxy { 私人只读MasterDetailPage r_MasterPage;
public MasterDetailProxy(MasterDetailPage i_MasterPage)
{
View = i_MasterPage;
r_MasterPage = i_MasterPage;
}
public object DetailNativeView
{
get
{
return r_MasterPage.Detail;
}
set
{
r_MasterPage.Detail = value as Page;
}
}
public object MasterNativeView
{
get
{
return r_MasterPage.Master;
}
set
{
Page page = value as Page;
if(string.IsNullOrEmpty(page.Title))
{
page.Title = "Please set your MasterPage Title";
}
r_MasterPage.Master = page;
}
}
public object View { get; set; }
}
我正在使用它在主人和详细信息部分的页面上显示菜单。 我的菜单视图是
<base:PageProxy xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:base="clr-namespace:Exrin.Base;assembly=Exrin.Base"
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"
xmlns:control="clr-namespace:BeAttend.Control;assembly=BeAttend"
x:Class="BeAttend.View.MenuView" Title="Menu">
<base:PageProxy.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" >Icon-Small.png</On>
</OnPlatform>
</base:PageProxy.Icon>
<ContentPage.Content>
<Grid BackgroundColor="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<Image Source="menubg.jpg" Aspect="AspectFill" />
<StackLayout Padding="0,20,0,0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" >
<controls:CircleImage BorderColor="White" BorderThickness="2" Source="{Binding VisualState.User.Picture}" Aspect="AspectFit" WidthRequest="100" HeightRequest="100" />
<Label Text="{Binding VisualState.User.Name}" TextColor="White" FontSize="Large" />
</StackLayout>
</Grid>
<StackLayout Margin="20,20,20,0" Grid.Row="1" Spacing="15">
<control:NavigationItem Text="Dashboard" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="Dashboard" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="Beacons" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="Beacons" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="Create event" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="CreateEvent" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="My events" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="MyEvents" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="Registered events" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="RegisteredEvents" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="Attendance QR" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="AttendanceQr" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="Join Event" Icon="fa-archive" Command="{Binding NavigationCommand}" CommandParameter="JoinEvent" />
<ContentView HeightRequest="1" BackgroundColor="Gray" />
<control:NavigationItem Text="Logout" Icon="fa-arrow-circle-left" Command="{Binding LogoutCommand}" />
</StackLayout>
</Grid>
</ContentPage.Content>
</base:PageProxy>
我有几个问题: 1.在Android上我自动拥有汉堡包菜单按钮但在iOS上我没有任何图标,我尝试使用
设置iOS菜单视图的图标<base:PageProxy.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" >Icon-Small.png</On>
</OnPlatform>
</base:PageProxy.Icon>
菜单视图上的但它不起作用。 2.在iOS上,页面标题为“请设置您的MasterPage标题”(如果页面标题为空,代理设置它),但您可以在菜单视图中看到我为页面设置标题,这仅在iOS上发生。 https://drive.google.com/file/d/0B3YFjr58f7_OMC04Y0FreVRvVlE/view?usp=sharing
当按下菜单上的链接时,我希望母版页消失,它当前保持打开并隐藏详细信息页面的一部分,直到我按下详细信息页面。
在详细信息页面上我有一个后退按钮,所以如果我要导航到另一个页面,我必须先按回来然后我会看到菜单图标以显示母版页面并选择另一个链接。如何更换后退按钮以始终显示汉堡包菜单按钮? 这是我的堆栈
公共类MainStack:BaseStack { public MainStack(IViewService i_ViewService) :base(new NavigationProxy(new NavigationPage()),i_ViewService,eStack.Main,nameof(Views.eMain.Dashboard)) { ShowNavigationBar = true; }
protected override void Map()
{
NavigationMap<DashboardView, DashboardViewModel>(nameof(Views.eMain.Dashboard));
NavigationMap<BeaconsView, BeaconsViewModel>(nameof(Views.eMain.Beacons));
NavigationMap<BeaconAddView, BeaconAddViewModel>(nameof(Views.eMain.AddBeacon));
NavigationMap<BeaconEditView, BeaconEditViewModel>(nameof(Views.eMain.EditBeacon));
NavigationMap<EventCreateView, EventCreateViewModel>(nameof(Views.eMain.CreateEvent));
NavigationMap<EventsCreatedView, EventsCreatedViewModel>(nameof(Views.eMain.MyEvents));
NavigationMap<EventsRegisteredView, EventsRegisteredViewModel>(nameof(Views.eMain.RegisteredEvents));
NavigationMap<EventEditView, EventEditViewModel>(nameof(Views.eMain.EditEvent));
NavigationMap<EventView, EventViewModel>(nameof(Views.eMain.ViewEvent));
NavigationMap<AttendanceQrView, AttendanceQrViewModel>(nameof(Views.eMain.AttendanceQr));
NavigationMap<JoinEventView, JoinEventViewModel>(nameof(Views.eMain.JoinEvent));
}
}
答案 0 :(得分:1)
如果要在单击链接时删除母版页,您会发现在IMasterDetailContainer中有一个名为IsPresented的属性。将此设置为true或false,以手动显示或隐藏页面。
如果您设置了ContentPages的标题,则会替换正在设置的所有默认标题。
确保Icon位于Resources文件夹中。此外,如果iOS中仍未显示,请将图标设置为Detail,Navigation或ContentPage。我无法记住你打算将它设置为哪一个。但是,如果你尝试这样做,你可以找出哪一个有效。