2016-07-05 7 views
0

Ich habe die folgenden xml und ViewModel Quellcode. Ich arbeite an der radiogroup, wo ich zwei Radiobuttons (Male und Female) habe. Zunächst möchte ich Radio-Button ausgewählt werden (Standard). In meiner aktuellen Implementierung wird jedoch kein Optionsfeld angezeigt. Beide sind als nicht selected.I gezeigt bin mit MvvmCross Version 4.0RadioGroup-Implementierung in MVVMCross

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); 
    } 
} 

In den Setup.cs

registry.RegisterFactory(new MvxCustomBindingFactory<MvxAppCompatRadioGroup>("ItemSelected", view => new MyRadioItemSelectedBinding(view))); 
+0

, was Ihr macht "item_radio" Layout-Vorlage aussehen? – Plac3Hold3r

+0

Ich habe hinzugefügt, überprüfen Sie bitte Update – hotspring

Antwort

2

Das Thema scheint Sie zu ItemSelected statt SelectedItem banden zu sein.

Ihre xml Layout-Kontrolle sollte sein:

<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; SelectedItem SelectedItem" /> 
+0

Bitte überprüfen Sie meine Setup.cs, nur in der Frage hinzugefügt. – hotspring

+0

@hotspring, wie sieht 'MyRadioItemSelectedBinding' aus? Gibt es einen bestimmten Grund, warum Sie eine benutzerdefinierte Bindung über das bereits enthaltene SelectedItem verwenden müssen? – Plac3Hold3r

+0

Ich habe gerade 'SelectedItem' verwendet und es hat funktioniert! Ich habe MvvmCross 4.0 zu 4.2.1 aktualisiert und 'SelectedItem' – hotspring