MvxAdapter创建期间MvvmCross.Platform.Exceptions.MvxException bindingContext为null [英] MvvmCross.Platform.Exceptions.MvxException bindingContext is null during MvxAdapter creation
本文介绍了MvxAdapter创建期间MvvmCross.Platform.Exceptions.MvxException bindingContext为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将MVXActivity转换为MvxFragment,当我尝试对布局进行膨胀时,应用程序崩溃在创建MvxAdapter期间bindingContext为null-仅当将特定的绑定上下文放置在堆栈上时才创建适配器.
I tried to convert MVXActivity into MvxFragment , the application crashes when i try to inflate the layout bindingContext is null during MvxAdapter creation - Adapter's should only be created when a specific binding context has been placed on the stack
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
return inflater.Inflate(Resource.Layout.BrandView1, container, false);
}
我的布局如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Query SearchString" />
<MvxSpinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ProductSpinner"
android:layout_marginTop="20dp"
android:layout_marginLeft="40dp"
local:MvxItemTemplate="@layout/item_product"
local:MvxDropDownItemTemplate="@layout/item_product"
local:MvxBind="ItemsSource Products; SelectedItem SelectedProduct" />
<!--<Mvx.MvxListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource FilteredBrands"
local:MvxItemTemplate="@layout/item_brand" />-->
</LinearLayout>
推荐答案
我发现我需要使用BindingInflate.
I figured out that i need to use the BindingInflate .
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
this.EnsureBindingContextIsSet(inflater);
return this.BindingInflate(Resource.Layout.BrandView1, container, false);
}
这篇关于MvxAdapter创建期间MvvmCross.Platform.Exceptions.MvxException bindingContext为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文