Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ListBoxItem Class

Represents a selectable item in a ListBox.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public class ListBoxItem : ContentControl
public class ListBoxItem extends ContentControl
public class ListBoxItem extends ContentControl
<ListBoxItem>
  Content
</ListBoxItem>

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

Data bind a ListBoxItem by binding the ItemsSource property of a ListBox to a data source. For more information see How to: Bind a ListBox to Data. You can customize the appearance of a ListBoxItem by setting the ItemTemplate property of a ListBox to a DataTemplate. For more information, see Data Templating Overview.

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 will be centered.

Content Model: ListBoxItem is a ContentControl. For more information on the content model for ListBoxItem, see Content Control Content Model.

The following example shows how to create a ListBox that contains ListBoxItem elements.

<TextBox Name="tb" Width="140" Height="30"></TextBox>
<ListBox Name="lb" Width="100" Height="55" SelectionChanged="PrintText" SelectionMode="Single">
  <ListBoxItem>Item 1</ListBoxItem>
  <ListBoxItem>Item 2</ListBoxItem>
  <ListBoxItem>Item 3</ListBoxItem>
  <ListBoxItem>Item 4</ListBoxItem>
  <ListBoxItem>Item 5</ListBoxItem>
  <ListBoxItem>Item 6</ListBoxItem>
  <ListBoxItem>Item 7</ListBoxItem>
  <ListBoxItem>Item 8</ListBoxItem>
  <ListBoxItem>Item 9</ListBoxItem>
  <ListBoxItem>Item 10</ListBoxItem>
</ListBox>

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
               System.Windows.Controls.ContentControl
                System.Windows.Controls.ListBoxItem
                   System.Windows.Controls.ComboBoxItem
                   System.Windows.Controls.ListViewItem

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

Show:
© 2014 Microsoft