问题
但我收到一个异常,然后在运行时崩溃,此时应该显示此活动:
演示者词典
代码
这就是我的代码的样子,我是按照
Playground example
以及
Documentation
:
AppStart.cs:
public class AppStart : MvxAppStart
{
private readonly IMvxNavigationService _mvxNavigationService;
public AppStart(IMvxApplication app, IMvxNavigationService mvxNavigationService)
: base(app, mvxNavigationService)
{
_mvxNavigationService = mvxNavigationService;
}
protected override void NavigateToFirstViewModel(object hint = null)
{
Mvx.Resolve<IMvxNavigationService>().Navigate<TabLayoutViewModel>();
}
}
TabLayoutViewModel.cs表格
public class TabLayoutViewModel: MvxViewModel
{
public override async Task Initialize()
{
await base.Initialize();
var tasks = new List<Task>();
tasks.Add(Mvx.Resolve<IMvxNavigationService>().Navigate<FragmentTab1ViewModel>());
tasks.Add(Mvx.Resolve<IMvxNavigationService>().Navigate<FragmentTab2ViewModel>());
await Task.WhenAll(tasks);
}
}
片段tab1viewmodel.cs
(与FragmentTab2ViewModel.cs类似)
public class FragmentTab1ViewModel : MvxViewModel
{
public override Task Initialize()
{
return base.Initialize();
}
}
TabLayoutViewController.cs表格
[MvxActivityPresentation]
[Activity(Label = "", ScreenOrientation = ScreenOrientation.Portrait, LaunchMode = LaunchMode.SingleTask, Theme = "@style/LoginTheme")]
public class TabLayoutViewController: MvxAppCompatActivity<TabLayoutViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.TabLayoutView);
var set = this.CreateBindingSet<TabLayoutViewController, TabLayoutViewModel>();
set.Apply();
}
}
TabLayoutView.axml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alwaysDrawnWithCache="false"
android:background="#f4f4f4"
android:minWidth="25px"
android:minHeight="25px">
<android.support.design.widget.TabLayout
android:id="@+id/tabsTeste"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
app:tabGravity="center"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpagerTeste"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
FragmentTab1ViewController.cs
[MvxTabLayoutPresentation(ActivityHostViewModelType = typeof(TabLayoutViewModel), ViewPagerResourceId = Resource.Id.viewpagerTest, TabLayoutResourceId = Resource.Id.tabsTest, Title = "Tab A")]
[Register("smartSolution.coleta.droid.view.FragmentTab1ViewController")]
public class FragmentTab1ViewController : MvxFragment<FragmentTab1ViewModel>
{
public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.FragmentTab1View, null);
inflater.Inflate(Resource.Layout.FragmentTab1View, container, true);
var set = this.CreateBindingSet<FragmentTab1ViewController, FragmentTab1ViewModel>();
set.Apply();
return view;
}
}
(FragmentTab1View.axml和FragmentTab2View.axml只是带有文本视图的线性布局)
-
引发异常的原因是什么?
-
这是实现带有片段的TabLayout的推荐方法吗?
-
遵循mvvmcross6.x良好实践,可以做些什么来解决这个问题?