我目前正在使用来自XLabs的XLabs组件。我从示例中了解到,您可以通过向BindableRadioGroup.的ItemsSource属性提供字符串数组来设置单选按钮中的文本。
示例:
BindableRadioGroup buttonGroup = new BindableRadioGroup();
ansPicker.ItemsSource = new[]
{
"Red",
"Blue",
"Green",
"Yellow",
"Orange"
};现在,如果可以对一个对象做同样的事情,我想现在就做。
示例:
public class Person {
private string name;
private int age;
}如果我有这个Person对象的列表,我可以直接将它给BindableRadioGroup的BindableRadioGroup属性吗?如何定义将在CustomRadioButton上显示的属性?
我为一个ListView找到了这个方法,但在我的例子中,我找不到BindableRadioGroup的ItemTemplate属性:
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" }
};谢谢。
发布于 2016-06-01 09:44:21
BindableRadioGroup实际上是从StackLayout派生出来的,所以我不认为您将能够使用DataTemplate。
没有测试过这一点,你可以尝试两件事。查看代码,Text设置为OnItemsSourceChanged中的Item.ToString()。您可以为您的ToString()对象定义为person。
或者,您可以自己处理每个CustomRadioButton的创建,绑定Checked和Text等每个属性,并手动将每个CustomRadioButton添加到BindableRadioGroup对象中。
https://stackoverflow.com/questions/37562473
复制相似问题