2

Xamarin Forms で Prism を使用してアプリを作成しようとしています。

Xamarin フォームのバージョン: 2.3.3.175

プリズムバージョン: 6.2.0

ハンバーガー メニューは Android で動作しますが、UWP を実行するとアイコンが表示されず、メニューをナビゲートするとメニューが完全に消え、メソッドが他のページに戻ることもありません。つまり、アプリを閉じて再起動する必要があります。

これが私がこれまでに試したことです。

  1. プリズム プロジェクトを作成した後、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);
        }
    }
  1. その後、ナビゲーション ページと、それぞれのページとビュー モデルを作成しました。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>();
        }
    }
    
  2. UWPでアプリを実行すると、このように読み込まれます ここに画像の説明を入力

しかし、メニューのリンクをクリックすると、メニューが消えて、このようになります。

ここに画像の説明を入力

私が間違っていることと、どうすれば解決できますか?

エラーを簡単に表示できるように、github にプロジェクトを作成しました。

https://github.com/codemasterblackperl/Hamburger_Menu_Prism_Forms_Repo

4

3 に答える 3

0

これはあなたの質問に部分的にしか答えません。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>

完了すると、アイコンが表示されます。ただし、マスター内のアイテムをクリックすると、メニューが折りたたまれることがわかります。私はそれを修正できませんでした。

于 2016-12-19T07:20:50.067 に答える