汉堡菜单棱镜 xamarin 形式?
hamburger menu prism xamarin forms?
我正在尝试在 Xamarin Forms 中使用 Prism 创建一个应用程序。
Xamarin 表单版本: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 部分 class 应用: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 中的应用程序加载时是这样的
但是当我点击菜单中的链接时,菜单会消失,看起来像这样。
我做错了什么,我该如何解决?
我在github中创建了一个项目,所以你可以很容易地查看错误。
https://github.com/codemasterblackperl/Hamburger_Menu_Prism_Forms_Repo
这只能部分回答您的问题。看不到该图标也让我很困惑,尽管它记录在 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>
完成后,它会显示图标。但是,这将向您显示,一旦您单击母版中的某个项目,菜单就会折叠。我没能解决这个问题。
这是最新版本的 Xamarin 中的错误。它在使用 2.3.1.114 时有效。我已经发布了错误 here 因为我只是 运行 到这里。
只需在 MasterDetail 中使用 IMasterDetailPageOptions 接口 code-behind:
public partial class ShellView : MasterDetailPage, IMasterDetailPageOptions
{
public ShellView()
{
InitializeComponent();
}
public bool IsPresentedAfterNavigation
{
get { return Device.Idiom != TargetIdiom.Phone; }
}
}
我正在尝试在 Xamarin Forms 中使用 Prism 创建一个应用程序。
Xamarin 表单版本: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 部分 class 应用: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 中的应用程序加载时是这样的
但是当我点击菜单中的链接时,菜单会消失,看起来像这样。
我做错了什么,我该如何解决?
我在github中创建了一个项目,所以你可以很容易地查看错误。
https://github.com/codemasterblackperl/Hamburger_Menu_Prism_Forms_Repo
这只能部分回答您的问题。看不到该图标也让我很困惑,尽管它记录在 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>
完成后,它会显示图标。但是,这将向您显示,一旦您单击母版中的某个项目,菜单就会折叠。我没能解决这个问题。
这是最新版本的 Xamarin 中的错误。它在使用 2.3.1.114 时有效。我已经发布了错误 here 因为我只是 运行 到这里。
只需在 MasterDetail 中使用 IMasterDetailPageOptions 接口 code-behind:
public partial class ShellView : MasterDetailPage, IMasterDetailPageOptions
{
public ShellView()
{
InitializeComponent();
}
public bool IsPresentedAfterNavigation
{
get { return Device.Idiom != TargetIdiom.Phone; }
}
}