我正在尝试使用Xamarin.Android应用程序中的ReactiveUI绑定到Spinner . 要将项目添加到 Spinner ,我需要使用 ArrayAdapter . 但 ArrayAdapter 需要 Android.Content.Context . 我应该将它传递给ViewModel吗?
任何人都知道用Xamarin.Android编写的应用程序,它使用ReactiveUI,在那里我可以看到灵感? ReactiveUI文档仅引用了为iOS编写的示例应用程序 .
查看
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:id="@+id/Label"
android:text="Zařízení:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:id="@+id/Devices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/Label"/>
android:id="@+id/EditCommand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/Devices"
android:text="Edit"/>
活动
namespace Test.Droid
{
[Activity(Label = "Test.Droid", MainLauncher = true)]
public class MainActivity : ReactiveActivity, IViewFor
{
public Spinner Devices { get; private set; }
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
ViewModel = new MainViewModel();
this.WireUpControls();
// Bindings
this.Bind(this.ViewModel, ) // ?
}
private MainViewModel _viewModel;
public MainViewModel ViewModel
{ get => _viewModel; set { this.RaiseAndSetIfChanged(ref _viewModel, value); } }
object IViewFor.ViewModel
{ get => ViewModel; set { ViewModel = (MainViewModel)value; } }
}
}
ViewModel
namespace Test.Droid.ViewModels
{
public class MainViewModel : ReactiveObject
{
// How to databind Spinner Devices ?
public MainViewModel()
{
}
}
}