簡體   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