【问题标题】:Xamarin Forms - XLabs CustomRadioButton : ItemsSourceXamarin 表单 - XLabs CustomRadioButton:ItemsSource
【发布时间】:2016-06-01 07:46:25
【问题描述】:

我目前正在使用 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" }
  };

谢谢。

【问题讨论】:

    标签: xamarin radio-button xamarin.forms itemssource xamarin.forms.labs


    【解决方案1】:

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

    如果没有对此进行测试,您可以尝试两件事。查看codeText 设置为Item.ToString()in OnItemsSourceChanged。您可以为您的person 对象定义一个ToString()

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-13
      相关资源
      最近更新 更多