SelectedItem Property

Selector.SelectedItem Property


Gets or sets the first item in the current selection or returns null if the selection is empty

Namespace:   System.Windows.Controls.Primitives
Assembly:  PresentationFramework (in PresentationFramework.dll)

public object SelectedItem { get; set; }

Property Value

Type: System.Object

The first item in the current selection or null if the selection is empty.

If a Selector supports selecting a single item, the SelectedItem property returns the selected item. If a Selector supports multiple selections, SelectedItem returns the item that the user selected first.

Setting SelectedItem in a Selector that supports multiple selections clears existing selected items and sets the selection to the item specified.

The following example gets the SelectedItem from a ListBox.

void PrintText(object sender, SelectionChangedEventArgs args)
    ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
    tb.Text = "   You selected " + lbi.Content.ToString() + ".";

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft