在以下代码中,我可以在微调器中显示CategoryList
项。
我的问题是,我怎么能够检测到哪一个被选中?
ViewModel.cs
public List<int> CategoryList
{
get { return new List<int> { 1,2,3,4,5,6,7,8,9,10 }; }
}
int _chosenCategory;
public int ChosenCategory {
get { return _chosenCategory; }
set { SetProperty(ref _chosenCategory, value);
}
}
ViewModel.axml
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent">
<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
android:layout_width="100dp"
android:layout_height="match_parent"
local:MvxItemTemplate="@layout/xxx"
local:MvxBind="ItemsSource CategoryList;SelectedItem ChosenCategory" />
</LinearLayout>
答案 0 :(得分:7)
您可以通过SelectedItem
<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatSpinner
android:layout_width="100dp"
android:layout_height="match_parent"
local:MvxItemTemplate="@layout/category_spinner"
local:MvxBind="ItemsSource CategoryList; SelectedItem ChosenCategory" />
并确保您在安装程序类中具有此功能:
public class Setup : MvxAndroidSetup
{
// ...
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
MvxAppCompatSetupHelper.FillTargetFactories(registry);
base.FillTargetFactories(registry);
}
}