I'm currently using the CustomRadioButton component from XLabs. I learned from the sample that you can set the text from the radio buttons by giving a string array to the ItemsSource property of the BindableRadioGroup.
Example :
BindableRadioGroup buttonGroup = new BindableRadioGroup();
ansPicker.ItemsSource = new[]
{
"Red",
"Blue",
"Green",
"Yellow",
"Orange"
};
Now, I would like to now if it is possible to do the same thing with an object.
Example :
public class Person {
private string name;
private int age;
}
If I have a List of this Person object, can I give it directly to the ItemsSource property of the BindableRadioGroup? How do I define which attribute will be display on the CustomRadioButton?
I found this method for a ListView but in my case, I can't find the ItemTemplate property for the BindableRadioGroup :
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" }
};
Thanks.
BindableRadioGroupis actually derived from aStackLayoutso I don't think you're going to be able to use aDataTemplate.Without having tested this you could try two things. Looking at the code,
Textis set toItem.ToString()inOnItemsSourceChanged. You could define to aToString()for yourpersonobject.Alternatively you could handle the creation of each
CustomRadioButtonyourself, binding each property such asCheckedandTextand manually add eachCustomRadioButtonto yourBindableRadioGroupobject.