Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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
C# MvxFragment中的FindViewById_C#_Android_Android Fragments_Mvvmcross - Fatal编程技术网

C# MvxFragment中的FindViewById

C# MvxFragment中的FindViewById,c#,android,android-fragments,mvvmcross,C#,Android,Android Fragments,Mvvmcross,我需要在MvxFragment中找到我在axml中声明的视图。在活动中,我可以在OnCreate中调用FindViewById(资源ID)。这在片段中不起作用 这是它如何处理普通Android片段的: 如何在不丢失绑定上下文的情况下在MvxFragment中膨胀视图?它就是这样工作的: 您需要了解两种扩展方法EnsureBindingContextIsSet()和BindingInflate() 公共类MyFragment:MvxFragment { CreateView上的公共覆盖视图(Lay

我需要在MvxFragment中找到我在axml中声明的视图。在活动中,我可以在
OnCreate
中调用
FindViewById(资源ID)
。这在片段中不起作用

这是它如何处理普通Android片段的:

如何在不丢失绑定上下文的情况下在
MvxFragment
中膨胀视图?

它就是这样工作的:

您需要了解两种扩展方法
EnsureBindingContextIsSet()
BindingInflate()

公共类MyFragment:MvxFragment
{
CreateView上的公共覆盖视图(LayoutInflater充气机、ViewGroup容器、Android.OS.Bundle savedInstanceState)
{
这将确保绑定上下文集(savedInstanceState);
var view=this.BindingInflate(Resource.Layout.YOUR_视图,container,false);
var searchField=view.findviewbyd(Resource.Id.Resource\u Id);
返回视图;
}
}
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;
    }
}