ListBoxItem Class
Collapse the table of content
Expand the table of content

ListBoxItem Class

Represents a selectable item in a ListBox.

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

public class ListBoxItem : ContentControl
public class ListBoxItem extends ContentControl
public class ListBoxItem extends ContentControl

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>


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

© 2015 Microsoft