我遇到了一个奇怪的问题,当我将内容页面设置为启动页面时,Xamarin Forms App 工作正常。如果我将 TabbedPage 设置为启动项并将相同的 ContentPage 设置为 TabbedPage 的子项,则它不会显示/数据绑定(bind) ContentPage。没有错误。我错过了什么想法?这是我的 TabbedPage View 模型。
using MvvmCross.Core.ViewModels;
using System.Windows.Input;
namespace Company.Mobile.ViewModels
{
public class TabbedMainViewModel
: MvxViewModel
{
}
}
XAML:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="using:Xamarin.Forms"
xmlns:local="clr-namespace:company.Mobile.Pages;assembly=company.Mobile"
x:Class="company.Mobile.Pages.TabbedMainPage"
Title="Title">
<TabbedPage.Children>
<local:HomePage/>
<local:MainPage/>
<local:ResourcesPage/>
<local:ContactPage/>
</TabbedPage.Children>
</TabbedPage>
最佳答案
经过大量试验和错误以及社区的帮助,这是有效的方法。
将 BindingContext 设置为 ContentPage 代码隐藏 C#,如下所示:
public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
var svc = Mvx.Resolve<IMobileService>();
BindingContext = new HomeViewModel(svc);
}
}
在 HomeViewModel 构造函数中获取数据,如下所示:
public class HomeViewModel : MvxViewModel
{
private readonly IMobileService service;
public HomeViewModel(IMobileService service)
{
this.service = service;
//Content = service.GetContent; //Get your data
}
}
关于android - 带有 Mvvmcross 的 Xamarin 表单选项卡式页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40187469/