j7n*_*n7k 2 c# android android-fragments mvvmcross
我需要在MvxFragment中找到我在axml中声明的视图.在我可以打电话的活动FindViewById<T>(RESOURCE_ID)中OnCreate.这不适用于片段.
这就是它如何与普通的Android片段一起使用:片段中的findViewById
如何在MvxFragment不丢失绑定上下文的情况下对视图进行充气?
这是它的工作原理:
您需要了解这两种扩展方法EnsureBindingContextIsSet()和BindingInflate().
public class MyFragment : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
{
this.EnsureBindingContextIsSet(savedInstanceState);
var view = this.BindingInflate(Resource.Layout.YOUR_VIEW, container, false);
var searchField = view.FindViewById<T>(Resource.Id.RESOURCE_ID);
return view;
}
}
Run Code Online (Sandbox Code Playgroud)