1

現在、XLabsのCustomRadioButtonコンポーネントを使用しています。サンプルから、BindableRadioGroupのItemsSourceプロパティに文字列配列を渡して、ラジオボタンからテキストを設定できることを学びました。Xamarinフォーム - XLabs CustomRadioButton:ItemsSource

例:今すぐ

BindableRadioGroup buttonGroup = new BindableRadioGroup(); 
ansPicker.ItemsSource = new[] 
     { 
      "Red", 
      "Blue", 
      "Green", 
      "Yellow", 
      "Orange" 
     }; 

オブジェクトと同じことを行うことが可能であるならば、私は今したいと思います。

例:

public class Person { 
    private string name; 
    private int age; 
} 

私はこのオブジェクトのリストを持っている場合、私は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" } 
    }; 

感謝。

答えて

2

BindableRadioGroupは実際にはStackLayoutから派生していますので、DataTemplateを使用できるとは思われません。

これをテストすることなく、2つのことを試すことができます。 codeを見ると、TextItem.ToString()に設定され、OnItemsSourceChangedに設定されています。 personオブジェクトの場合、ToString()と定義できます。

代わりに次のようなCheckedText、手動で追加する各CustomRadioButtonあなたBindableRadioGroup対象に各プロパティをバインディング、自分を各CustomRadioButtonの作成を扱うことができます。