0

我在 exrin 中使用 MasterDetailPage 这是我的 ViewContainer 公共类 MainViewContainer : Exrin.Framework.ViewContainer, IMasterDetailContainer { private readonly 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 { private readonly 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

  1. 当按下菜单上的链接时,我希望母版页消失,它当前保持打开并隐藏部分详细信息页面,直到我按下详细信息页面。

  2. 在详细信息页面上,我有一个返回按钮,所以如果我想导航到另一个页面,我必须先按返回,然后我可以看到菜单图标以显示主页面并选择另一个链接。如何替换后退按钮以始终显示汉堡菜单按钮?这是我的堆栈

    公共类 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));
        }
    }
    
4

1 回答 1

1
  1. 如果你想在点击链接的时候移除Master页面,你会发现在你的IMasterDetailContainer中,有一个叫做IsPresented的属性。将此设置为 true 或 false,以手动显示或隐藏页面。

  2. 如果您设置 ContentPages 的标题,这将替换任何正在设置的默认标题。

  3. 确保图标在您的资源文件夹中。此外,如果它仍未在 iOS 中显示,请将图标设置为 Detail、Navigation 或 ContentPage。我不记得您打算将其设置为哪个。但是,如果您尝试这样做,您会发现哪个有效。

于 2017-09-04T03:51:33.420 回答