Android 带有Mvvmcross的Xamarin表单选项卡式页面
我有一个奇怪的问题,Xamarin Forms应用程序在我将内容页设置为启动页时运行良好。如果我将TabbedPage设置为启动,将ContentPage设置为TabbedPage的子级,则它不会显示/data bind ContentPage。没有错误。我有什么不知道的?这是我的选项卡式页面视图模型Android 带有Mvvmcross的Xamarin表单选项卡式页面,android,xamarin,visual-studio-2015,xamarin.forms,mvvmcross,Android,Xamarin,Visual Studio 2015,Xamarin.forms,Mvvmcross,我有一个奇怪的问题,Xamarin Forms应用程序在我将内容页设置为启动页时运行良好。如果我将TabbedPage设置为启动,将ContentPage设置为TabbedPage的子级,则它不会显示/data bind ContentPage。没有错误。我有什么不知道的?这是我的选项卡式页面视图模型 using MvvmCross.Core.ViewModels; using System.Windows.Input; namespace Company.Mobile.ViewModels
using MvvmCross.Core.ViewModels;
using System.Windows.Input;
namespace Company.Mobile.ViewModels
{
public class TabbedMainViewModel
: MvxViewModel
{
}
}
XAML:
经过大量的尝试和错误,以及社区的帮助,以下是有效的方法 将BindingContext设置为C#后面的ContentPage代码,如下所示:
public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
var svc = Mvx.Resolve<IMobileService>();
BindingContext = new HomeViewModel(svc);
}
}
我想说的是,通过在XAML中为每个您的选项卡页面添加这个内联属性,您可以更轻松地做到这一点,例如,对于主页,它应该是
BindingContext=“{Binding HomePageViewModel}”
嗨,我知道这已经很久了。但是在MvvmCross-xamarin表单中使用选项卡式页面有什么解决方案吗。
public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
var svc = Mvx.Resolve<IMobileService>();
BindingContext = new HomeViewModel(svc);
}
}
public class HomeViewModel : MvxViewModel
{
private readonly IMobileService service;
public HomeViewModel(IMobileService service)
{
this.service = service;
//Content = service.GetContent; //Get your data
}
}