繁体   English   中英

Xamarin表单-XLabs CustomRadioButton:ItemsSource

[英]Xamarin Forms - XLabs CustomRadioButton : ItemsSource

我目前正在使用XLabs的CustomRadioButton组件。 我从样本中了解到,可以通过为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的ItemsSource属性? 如何定义哪个属性将显示在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" }
  };

谢谢。

BindableRadioGroup实际上是从StackLayout派生的,所以我认为您将无法使用DataTemplate

未经测试,您可以尝试两种方法。 查看代码 ,在OnItemsSourceChanged Text设置为Item.ToString() 您可以为您的person对象定义一个ToString()

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM