【问题标题】:hamburger menu prism xamarin forms?汉堡菜单棱镜 xamarin 形式?
【发布时间】:2017-05-04 03:17:14
【问题描述】:

我正在尝试在 Xamarin Forms 中使用 Prism 创建一个应用程序。

Xamarin 表单版本:2.3.3.175

棱镜版本:6.2.0

汉堡菜单在 Android 中有效,但是当我在 UWP 上运行它时,它不会显示图标,而且当我浏览菜单时,菜单完全消失,我也不会让该方法返回到其他页面。换句话说,我需要关闭并重新启动应用程序。

这是我目前尝试过的。

  1. 创建 prism 项目后,我添加了一个 MasterDetailPage:

    <MasterDetailPage.Master>
        <ContentPage Title="Default">
            <StackLayout>
                <Button Text="Billing" Command="{Binding Path=NavigationCommand}" CommandParameter="MyNavigationPage/BillingPage"/>
                <Button Text="Your Order" Command="{Binding Path=NavigationCommand}" CommandParameter="MyNavigationPage/PlaceOrderPage"/>
                <Button Text="Settings" Command="{Binding Path=NavigationCommand}" CommandParameter="MyNavigationPage/SettingsPage"/>
                <Button Text="Settings"/>
            </StackLayout>
        </ContentPage>
    </MasterDetailPage.Master>
    

MasterDetailPage 视图模型

public class MDPageViewModel : BindableBase
    {
        private INavigationService _navigationService;


        public DelegateCommand<string> NavigationCommand => new DelegateCommand<string>(Navigation);



        public MDPageViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;

        }

        private void Navigation(string page)
        {
            _navigationService.NavigateAsync(page);
        }
    }
  1. 之后我创建了一个导航页面以及相应的页面和视图模型。这是 App.Xaml.cs 文件:

    公共部分类 App : PrismApplication { 公共应用程序(IPlatformInitializer 初始化程序 = null):基础(初始化程序){}

        protected override void OnInitialized()
        {
            InitializeComponent();
    
            NavigationService.NavigateAsync("MDPage/MyNavigationPage/ItemsPage");
        }
    
        protected override void RegisterTypes()
        {
            Container.RegisterTypeForNavigation<MDPage>();
            Container.RegisterTypeForNavigation<BillingPage>();
            Container.RegisterTypeForNavigation<PlaceOrderPage>();
            Container.RegisterTypeForNavigation<SettingsPage>();
            Container.RegisterTypeForNavigation<MyNavigationPage>();
        }
    }
    
  2. 所以当我在 UWP 中运行应用程序时,它会像这样加载

但是当我点击 menu 中的链接时,menu 会消失,看起来像这样。

我做错了什么,我该如何解决?

我在github上创建了一个项目,方便大家查看错误。

https://github.com/codemasterblackperl/Hamburger_Menu_Prism_Forms_Repo

【问题讨论】:

    标签: c# xamarin xamarin.forms prism prism-6


    【解决方案1】:

    这是最新版本的 Xamarin 中的一个错误。它在使用 2.3.1.114 时有效。我已经发布了错误here,因为我刚刚遇到了这个问题。

    【讨论】:

      【解决方案2】:

      这只会部分回答您的问题。虽然 Prism.Forms 文档中记录了该图标,但无法看到该图标也让我感到困惑。要获取图标,请转到 UWP 项目中的 App.Xaml,并在 &lt;Application.Resources&gt;...&lt;/Application.Resources&gt;

      之间添加以下数据模板
      <DataTemplate x:Key="ItemTemplate">
          <uwp:ItemControl HorizontalContentAlignment="Stretch"
                           VerticalContentAlignment="Stretch" />
      </DataTemplate>
      

      在顶部定义 uwp 前缀,例如 xmlns:uwp="using:Xamarin.Forms.Platform"

      您的 App.Xaml 应如下所示:

      <Application x:Class="MyApp.App"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:uwp="using:Xamarin.Forms.Platform">
      <Application.Resources>
          <DataTemplate x:Key="ItemTemplate">
              <uwp:ItemControl HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch" />
          </DataTemplate>
      </Application.Resources>
      

      完成后,它将显示图标。但是,这将告诉您,一旦您单击主文件中的项目,菜单就会折叠。我无法解决这个问题。

      【讨论】:

      【解决方案3】:

      只需在 MasterDetail 代码隐藏中使用 IMasterDetailPageOptions 接口:

      public partial class ShellView : MasterDetailPage, IMasterDetailPageOptions
      {
          public ShellView()
          {
              InitializeComponent();
          }
      
          public bool IsPresentedAfterNavigation
          {
              get { return Device.Idiom != TargetIdiom.Phone; }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-08-16
        • 1970-01-01
        • 2019-04-19
        • 2018-11-09
        • 2021-10-20
        • 2019-10-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多