共用方式為


RadioButtons.ItemsSource 屬性

定義

取得或設定用來產生控件內容的物件來源。

public:
 property Platform::Object ^ ItemsSource { Platform::Object ^ get(); void set(Platform::Object ^ value); };
IInspectable ItemsSource();

void ItemsSource(IInspectable value);
public object ItemsSource { get; set; }
var object = radioButtons.itemsSource;
radioButtons.itemsSource = object;
Public Property ItemsSource As Object

屬性值

Object

Platform::Object

IInspectable

用來產生控件內容的物件。 預設值為 null

範例

這個範例會示範如何將控制項繫結至自訂資料來源。

 <RadioButtons Header="Background color"
                    SelectionChanged="BackgroundColor_SelectionChanged"
                    ItemsSource="{x:Bind colorOptionItems}"/>

...

<Border x:Name="ExampleBorder" Width="100" Height="100"/>
public sealed partial class MainPage : Page
{
    // Custom data item.
    public class ColorOptionDataModel
    {
        public string Label { get; set; }
        public SolidColorBrush ColorBrush { get; set; }

        public override string ToString()
        {
            return Label;
        }
    }

    List<ColorOptionDataModel> colorOptionItems;

    public MainPage1()
    {
        this.InitializeComponent();

        colorOptionItems = new List<ColorOptionDataModel>();
        colorOptionItems.Add(new ColorOptionDataModel()
            { Label = "Red", ColorBrush = new SolidColorBrush(Colors.Red) });
        colorOptionItems.Add(new ColorOptionDataModel()
            { Label = "Green", ColorBrush = new SolidColorBrush(Colors.Green) });
        colorOptionItems.Add(new ColorOptionDataModel()
            { Label = "Blue", ColorBrush = new SolidColorBrush(Colors.Blue) });
    }

    private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var option = e.AddedItems[0] as ColorOptionDataModel;
        ExampleBorder.Background = option?.ColorBrush;
    }
}

備註

如需詳細資訊、設計指引和程式碼範例,請參閱 單選按鈕

如需 ItemsSource 屬性行為的詳細資訊,請參閱 ItemsControl.ItemsSource

適用於

另請參閱