我有以下xml
和ViewModel
源代碼。我正在研究radiogroup
,我有兩個單選按鈕(男性和女性)。最初,我想要選擇Male
單選按鈕(默認)。但是,我目前的實現並沒有顯示任何單選按鈕被選中。他們兩個都顯示爲未selected.I現在用MvvmCross版本4.0MVVMCross中的RadioGroup實現
XML
<mvvmcross.droid.support.v7.appcompat.widget.MvxAppCompatRadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
local:MvxItemTemplate="@layout/item_radio"
local:MvxBind="ItemsSource Items;ItemSelected SelectedItem" />
Item_radio.xml
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
local:MvxBind="Text Caption" />
ViewModel.cs
private List<Thing> _items = new List<Thing>()
{
new Thing("Male"),
new Thing("Female"),
};
public List<Thing> Items
{
get { return _items; }
set { _items = value; RaisePropertyChanged(() => Items); }
}
private Thing _selectedItem = new Thing("Male");
public Thing SelectedItem
{
get
{
return _selectedItem;
}
set
{
_selectedItem = value;
RaisePropertyChanged(() => SelectedItem);
}
}
在Setup.cs
registry.RegisterFactory(new MvxCustomBindingFactory<MvxAppCompatRadioGroup>("ItemSelected", view => new MyRadioItemSelectedBinding(view)));
那麼你的 「item_radio」 佈局模板是什麼樣子? – Plac3Hold3r
我已添加,請檢查更新 – hotspring