Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 2
ListBoxItem Class

  Switch on low bandwidth view
Other versions are also available for the following:
.NET Framework Class Library for Silverlight
ListBoxItem Class

Represents a selectable item in a ListBox.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
<TemplateVisualStateAttribute(Name := "Normal", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Focused", GroupName := "FocusStates")> _
<TemplateVisualStateAttribute(Name := "MouseOver", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Disabled", GroupName := "CommonStates")> _
<TemplateVisualStateAttribute(Name := "Unselected", GroupName := "SelectionStates")> _
<TemplateVisualStateAttribute(Name := "Selected", GroupName := "SelectionStates")> _
<TemplateVisualStateAttribute(Name := "SelectedUnfocused", GroupName := "SelectionStates")> _
<TemplateVisualStateAttribute(Name := "Unfocused", GroupName := "FocusStates")> _
Public Class ListBoxItem _
    Inherits ContentControl
Visual Basic (Usage)
Dim instance As ListBoxItem
C#
[TemplateVisualStateAttribute(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Focused", GroupName = "FocusStates")]
[TemplateVisualStateAttribute(Name = "MouseOver", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Disabled", GroupName = "CommonStates")]
[TemplateVisualStateAttribute(Name = "Unselected", GroupName = "SelectionStates")]
[TemplateVisualStateAttribute(Name = "Selected", GroupName = "SelectionStates")]
[TemplateVisualStateAttribute(Name = "SelectedUnfocused", GroupName = "SelectionStates")]
[TemplateVisualStateAttribute(Name = "Unfocused", GroupName = "FocusStates")]
public class ListBoxItem : ContentControl
XAML Object Element Usage
<ListBoxItem .../>
-or-
<listboxitem ...>
  content
</listboxitem>

XAML Values

content

A single object element that serves as content.

listboxitem

A ListBoxItem object element, or an object element for a class that derives from ListBoxItem.

A ListBox contains a collection of ListBoxItem objects. To select a ListBoxItem in a ListBox, set the IsSelected property to true.

Bind a ListBoxItem to data by binding the ItemsSource property of a ListBox to a data source.

You can customize the appearance of a ListBoxItem by setting the ItemTemplate property of a ListBox to a DataTemplate.

By default, the HorizontalAlignment of a ListBoxItem is set to Stretch. The default horizontal position of a StackPanel is Center. If you set the Width property of a ListBoxItem through a StackPanel, the panel's default is applied and the item is centered. ListBoxItem is a ContentControl. Its content property is Content.

The following example shows how to add ListBoxItem objects directly to a ListBox control using XAML.

<ListBox Width="350" Margin="0,5,0,5" SelectionChanged="PrintText" >
    <ListBoxItem Content="Item 1" />
    <ListBoxItem Content="Item 2" />
    <ListBoxItem Content="Item 3" />
    <ListBoxItem Content="Item 4" />
    <ListBoxItem Content="Item 5" />
</ListBox>
<TextBlock Name="textBlock1" />

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker