首页 文章

汉堡菜单棱镜xamarin形式?

提问于
浏览
2

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

Xamarin Forms版本:2.3.3.175

棱镜版本:6.2.0

汉堡包菜单适用于Android,但是当我运行UWP时,它不会显示图标,当我浏览菜单时,菜单完全消失,我也不会将方法返回到其他页面 . 换句话说,我需要关闭并重新启动应用程序 .

这是我到目前为止所尝试的 .

  • 创建棱镜项目后,我添加了一个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 ViewModel

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);
        }
    }
  • 之后我创建了一个导航页面以及相应的页面和视图模型 . 这是App.Xaml.cs文件:

public partial class App:PrismApplication {public App(IPlatformInitializer initializer = null):base(initializer){}

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>();
    }
}
  • 所以当我在UWP中运行应用程序时,它会像这样加载
    enter image description here

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

enter image description here

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

我在github中创建了一个项目,因此您可以轻松查看错误 .

https://github.com/codemasterblackperl/Hamburger_Menu_Prism_Forms_Repo

3 回答

  • 0

    这是最新版Xamarin中的一个错误 . 它在使用2.3.1.114时有效 . 我发布了错误here,因为我刚刚碰到这个 .

  • 0

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

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

    这只会部分回答您的问题 . 虽然它已经在Prism.Forms文档中记录,但是无法看到图标也让我感到高兴 . 要获取图标,请转到UWP项目中的App.Xaml,并在 <Application.Resources>...</Application.Resources> 之间添加以下数据模板

    <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>
    

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

相关问题