C# 使用带有FreshMvvm的工具栏项导航到选项卡页
我想知道如何使用C# 使用带有FreshMvvm的工具栏项导航到选项卡页,c#,xamarin,xamarin.forms,freshmvvm,C#,Xamarin,Xamarin.forms,Freshmvvm,我想知道如何使用ToolBarItem单击调用我的TabbedNavigationContainer的特定选项卡页面。我有一个BaseContentPage基类 public class BaseContentPage : ContentPage, IPage { public BaseContentPage() { ToolbarItems.Add(new ToolbarItem("Main Page", null, () => {
ToolBarItem
单击调用我的TabbedNavigationContainer
的特定选项卡页面。我有一个BaseContentPage
基类
public class BaseContentPage : ContentPage, IPage
{
public BaseContentPage()
{
ToolbarItems.Add(new ToolbarItem("Main Page", null, () =>
{
//Application.Current.MainPage = ??;
}));
}
}
所有页面都从中派生
public class App : Application
{
public App()
{
Registrations();
InitializeGui();
}
private void Registrations()
{
//FreshIOC.Container.Register<IFreshNavigationService
}
private void InitializeGui()
{
var tabbedNavigationContainer = new FreshTabbedNavigationContainer();
tabbedNavigationContainer.AddTab<MapPageModel>("Map", "icon.png");
tabbedNavigationContainer.AddTab<HistoryPageModel>("History", "icon.png");
MainPage = tabbedNavigationContainer;
}
}
公共类应用程序:应用程序
{
公共应用程序()
{
注册();
初始化gui();
}
私人无效注册()
{
//FreshIOC.Container.Register我不完全确定您的项目的结构,但我认为您正在尝试将导航添加到实际页面后面的代码中,对吗?虽然您可以这样做,但这有点违反MVVM原则。如果您仍然想这样做,您可能必须这样做:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" Title="MyPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Main Page" Command="{Binding GoToMainPageCommand}" />
</ContentPage.ToolbarItems>
<!-- ... Rest of page ... -->
</ContentPage>
FreshIOC.Container.Resolve().PushPage(FreshPageModelResolver.ResolvePageModel(null),null);
虽然它应该起作用,但它不是最好的方法
您应该为工具栏项
指定可绑定的命令
属性,并在其后面创建一个实现该命令的页面模型
我假设您使用的是XAML,因此您的XAML将如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" Title="MyPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Main Page" Command="{Binding GoToMainPageCommand}" />
</ContentPage.ToolbarItems>
<!-- ... Rest of page ... -->
</ContentPage>
现在您正以真正的MVVM方式导航到它