RadioButtons.ItemsSource Eigenschaft

Definition

Dient zum Abrufen oder Festlegen einer Objektquelle, die zum Generieren des Inhalts des Steuerelements verwendet wird.

Diese Dokumentation gilt für WinUI 2 für UWP (für WinUI im Windows App SDK, siehe Windows App SDK Namespaces).

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

void ItemsSource(IInspectable value);
public object ItemsSource { get; set; }
Public Property ItemsSource As Object

Eigenschaftswert

Object

Platform::Object

IInspectable

Das Objekt, das zum Generieren des Inhalts des Steuerelements verwendet wird. Der Standardwert ist null.

Beispiele

Dieses Beispiel veranschaulicht, wie Sie das Steuerelement an eine benutzerdefinierte Datenquelle binden können.

<!-- xmlns:muxc="using:Microsoft.UI.Xaml.Controls -->
 <muxc: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;
    }
}

Hinweise

Weitere Informationen, Entwurfsanleitungen und Codebeispiele finden Sie unter Optionsfelder.

Weitere Informationen zum Verhalten der ItemsSource-Eigenschaft finden Sie unter ItemsControl.ItemsSource.

Gilt für:

Weitere Informationen