我能够将数组_limitQuickPosts
绑定到我的微调器。但是我很难弄清楚如何将Selected绑定到我的_selectedLimitQuickPosts
。无论我做什么,我都无法让所选的值为"显示最近200篇帖子"。
Core ViewModel:
private string[] _limitQuickPosts = new string[4]
{
"Show last 25 Posts",
"Show last 50 Posts",
"Show last 100 Posts",
"Show last 200 Posts"
};
public string[] LimitQuickPosts
{
get { return _limitQuickPosts; }
set { _limitQuickPosts = value; RaisePropertyChanged(() => LimitQuickPosts); }
}
private string _selectedLimitQuickPosts = "Show last 200 Posts";
public string SelectedLimitQuickPosts
{
get { return _selectedLimitQuickPosts; }
set { _selectedLimitQuickPosts = value; RaisePropertyChanged(() => SelectedLimitQuickPosts); }
}
Droid布局:
<MvxSpinner
android:layout_width="210dp"
android:layout_height="wrap_content"
android:textSize="40dp"
android:id="@+id/limitSelect"
android:minWidth="50dp"
android:layout_marginLeft="10dp" />
Droid View:
...
var limitSelect = fragView.FindViewById<MvxSpinner>(Resource.Id.limitSelect);
...
...
set.Bind(limitSelect).For(x => x.ItemsSource).To(vm => vm.LimitQuickPosts);
set.Bind(limitSelect).For(x => x.Selected).To(vm => vm.SelectedLimitQuickPosts);
虽然它适当地将LimitQuickPosts
绑定到Spinner,并且我可以看到所有可用的选择,但我仍然不知道Selected如何绑定以及我必须做些什么才能正确绑定?
答案 0 :(得分:1)
请参阅此问题:Issue binding to MVXSpinner after upgrading to Mvvmcross v4.0.0-beta3
您必须从Setup.cs的FillTargetFactories()
中调用MvxAppCompatSetupHelper.FillTargetFactories
答案 1 :(得分:0)
问题是:
set.Bind(limitSelect).For(x => x.Selected).To(vm => vm.SelectedLimitQuickPosts);
应该是:
set.Bind(limitSelect).For(x => x.SelectedItem).To(vm => vm.SelectedLimitQuickPosts);
将Selected替换为SelectedItem并且工作正常