首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XLabs CustomRadioButton : ItemsSource

XLabs CustomRadioButton : ItemsSource
EN

Stack Overflow用户
提问于 2016-06-01 07:46:25
回答 1查看 1.9K关注 0票数 1

我目前正在使用来自XLabs的XLabs组件。我从示例中了解到,您可以通过向BindableRadioGroup.的ItemsSource属性提供字符串数组来设置单选按钮中的文本。

示例:

代码语言:javascript
复制
BindableRadioGroup buttonGroup = new BindableRadioGroup();
ansPicker.ItemsSource = new[]
        {
            "Red",
            "Blue",
            "Green",
            "Yellow",
            "Orange"
        };

现在,如果可以对一个对象做同样的事情,我想现在就做。

示例:

代码语言:javascript
复制
public class Person {
    private string name;
    private int age;
}

如果我有这个Person对象的列表,我可以直接将它给BindableRadioGroup的BindableRadioGroup属性吗?如何定义将在CustomRadioButton上显示的属性?

我为一个ListView找到了这个方法,但在我的例子中,我找不到BindableRadioGroup的ItemTemplate属性:

代码语言:javascript
复制
var template = new DataTemplate (typeof (TextCell));
// We can set data bindings to our supplied objects.
  template.SetBinding (TextCell.TextProperty, "FullName");
  template.SetBinding (TextCell.DetailProperty, "Address");

  itemsView.ItemTemplate = template;
  itemsView.ItemsSource = new[] {
    new Person { FullName = "James Smith", Address = "404 Nowhere Street" },
    new Person { FullName = "John Doe", Address = "404 Nowhere Ave" }
  };

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-06-01 09:44:21

BindableRadioGroup实际上是从StackLayout派生出来的,所以我不认为您将能够使用DataTemplate

没有测试过这一点,你可以尝试两件事。查看代码Text设置为OnItemsSourceChanged中的Item.ToString()。您可以为您的ToString()对象定义为person

或者,您可以自己处理每个CustomRadioButton的创建,绑定CheckedText等每个属性,并手动将每个CustomRadioButton添加到BindableRadioGroup对象中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37562473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档