Data binding 在带有ReactiveUI的Xamarin.Android中,将ReactiveList绑定到微调器的正确方法是什么

Data binding 在带有ReactiveUI的Xamarin.Android中,将ReactiveList绑定到微调器的正确方法是什么,data-binding,xamarin.android,android-spinner,reactiveui,Data Binding,Xamarin.android,Android Spinner,Reactiveui,我看过以下参考资料 并尝试按如下方式绑定微调器 这是我的ViewModel课程 public class ExampleVM : ReactiveObject{ ReactiveList<ExampleTypeResult> _list; public ReactiveList<ExampleTypeResult> ExampleList { get { return _list; }

我看过以下参考资料 并尝试按如下方式绑定微调器

这是我的ViewModel课程

public class ExampleVM : ReactiveObject{
    ReactiveList<ExampleTypeResult> _list;
            public ReactiveList<ExampleTypeResult> ExampleList
            {
                get { return _list; }
                private set { this.RaiseAndSetIfChanged(ref _list, value); }
            }
    } 
public类示例vm:ReactiveObject{
反应列表_列表;
公共反应列表示例列表
{
获取{return\u list;}
私有集{this.RaiseAndSetIfChanged(ref_list,value);}
}
} 
这是我的片段类

public class ExampleFragment : ExampleBaseFragment<ExampleVM>{
private ReactiveList<ExampleTypeResult> ExampleList;
            Action<ReactiveList<ExampleTypeResult>> action =
                list =>
                {
                    var mItems = ExampleList.Select(n => n._Name).ToList();
                    var adater = new ArrayAdapter<string>(this.Activity, Android.Resource.Layout.SimpleSpinnerItem, mItems);
                    adater.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
                    FragmentExampleSpinner.Adapter = adater;
                };

         this.Bind(this.ViewModel, vm => vm.ExampleList, v => v.ExampleList, action)
        .DisposeWith(SubscriptionDisposables);
}
公共类ExampleFragment:ExampleBaseFragment{
私有反应列表示例列表;
行动=
列表=>
{
var mItems=ExampleList.Select(n=>n._Name).ToList();
var adater=new ArrayAdapter(this.Activity,Android.Resource.Layout.SimpleSpinnerItem,mItems);
SetDropDownViewResource(Android.Resource.Layout.SimpleSpinerDropDownItem);
FragmentExampleSpinner.Adapter=适配器;
};
this.Bind(this.ViewModel,vm=>vm.ExampleList,v=>v.ExampleList,action)
.处置(订阅的可处置文件);
}

但这并不奏效,甚至没有错误。我想知道如何将反应列表正确绑定到Android.Widget.Spinner?

您可以尝试在ViewModel中创建一个
ArrayAdapter
属性。然后使用此阵列适配器绑定微调器。
例如:

public class TheViewModel : ReactiveObject
{
    private ArrayAdapter theadapter;
    public ArrayAdapter Theadapter
    {
        get { return this.theadapter; }
        set { this.RaiseAndSetIfChanged(ref this.theadapter, value); }
    }
}
并在活动中设置适配器:

        var mItems = new ReactiveList<string>();
        mItems.Add("AAA");
        mItems.Add("BBB");
        mItems.Add("CCC");
        mItems.Add("DDD");
        mItems.Add("EEE");
        mItems.Add("FFF");
        ViewModel.Theadapter = new ArrayAdapter(this, Resource.Layout.SimpleSpinnerItem, mItems);
        this.OneWayBind(this.ViewModel, vm => vm.Theadapter, v => v.TheSpinner.Adapter);
var mItems=new ReactiveList();
添加(“AAA”);
添加(“BBB”);
添加(“CCC”);
添加(“DDD”);
添加(“EEE”);
添加(“FFF”);
ViewModel.Theadapter=新的ArrayAdapter(这是Resource.Layout.SimpleSpinnerItem,mItems);
this.OneWayBind(this.ViewModel,vm=>vm.Theadapter,v=>v.TheSpinner.Adapter);

你好,谢谢你的回答。ArrayAdapter包含在Android.widget中。如何将其放入viewmodel类中。@GayanBuddhika是否要将数据设置为viewmodel类中的ArrayAdapter?您可以创建一个
构造函数来执行此操作。您可以参考此链接:您好,我的观点是我无法在viewmodel类中创建ArrayAdapter类型属性,因为我的viewmodels位于一个单独的C#Library项目中。我不能在那里使用Android设备。有吗solution@GayanBuddhika您是否尝试过创建继承您的
viewmodel
的类?