How to retrieve the selected value of a RadioGroup

190 Views Asked by At

Considering the code below (Xamarin - c#), how would you retrive the selected value of the RadioGroup?

var root = new RootElement ("Meals") {
    new Section ("Dinner"){
        new RootElement ("Dessert", new RadioGroup ("dessert", 2)) {
            new Section () {
                new RadioElement ("Ice Cream", "dessert"),
                new RadioElement ("Milkshake", "dessert"),
                new RadioElement ("Chocolate Cake", "dessert")
            }
        }
     }
}

Thank you

1

There are 1 best solutions below

2
Sergio Schirmer On BEST ANSWER

I stopped coding for a while and when I came back I realized how to do it:

    private void Save()
    {
        List<Element> elementList = new List<Element> ();
        elementList = Root [1].Elements;
        foreach (Element element in elementList) {
            RootElement radioElement = (RootElement)element;
            user.Title = radioElement[0].Elements[radioElement.RadioSelected].Caption;
        }
        user.Save ();
    }