【问题标题】:How to retrieve the selected value of a RadioGroup如何检索 RadioGroup 的选定值
【发布时间】:2015-07-24 02:55:53
【问题描述】:

考虑到下面的代码 (Xamarin - c#),您将如何检索 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")
            }
        }
     }
}

谢谢

【问题讨论】:

    标签: c# xamarin xamarin.ios monotouch.dialog


    【解决方案1】:

    我停止了一段时间的编码,当我回来时,我意识到该怎么做:

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

    【讨论】:

    • 您也可以将它们保存在一个类变量中(而不是在对象初始化程序中对其进行新建)并在尝试保存时直接访问它们。
    • 是的,这是有道理的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-03-21
    • 2011-09-20
    • 2012-04-08
    • 2016-08-14
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    相关资源
    最近更新 更多