Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有Mvvmcross的Xamarin表单选项卡式页面_Android_Xamarin_Visual Studio 2015_Xamarin.forms_Mvvmcross - Fatal编程技术网

Android 带有Mvvmcross的Xamarin表单选项卡式页面

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

我有一个奇怪的问题,Xamarin Forms应用程序在我将内容页设置为启动页时运行良好。如果我将TabbedPage设置为启动,将ContentPage设置为TabbedPage的子级,则它不会显示/data bind ContentPage。没有错误。我有什么不知道的?这是我的选项卡式页面视图模型

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