ListViewItem Class
Updated: February 2009
Represents an item in a ListView control.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Content Model: ListViewItem is a ContentControl. Its content property is Content. For more information on the content model for ListViewItem, see Controls Content Model Overview.
A ListView typically specifies the content for its ListViewItem controls by setting the ItemsSource property or the Items property. For an example, see ListView That Uses a GridView with Templates Sample.
Templates and styles that are defined for the ListViewItem type are used to specify the display of the content in a ListView. For an example, see ListView with Styled ListViewItems Sample.
Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.
This example shows how to define Triggers for a ListViewItem control so that when a property value of a ListViewItem changes, the Style of the ListViewItem changes in response.
If you want the Style of a ListViewItem to change in response to property changes, define Triggers for the Style change.
The following example defines a Trigger that sets the Foreground property to Blue and changes the Cursor to display a Hand when the IsMouseOver property changes to true.
<Style x:Key="MyContainer" TargetType="{x:Type ListViewItem}"> <Setter Property="Margin" Value="0,1,0,0"/> <Setter Property="Height" Value="21"/> <Style.Triggers> ... <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Foreground" Value="Blue" /> <Setter Property="Cursor" Value="Hand"/> </Trigger> ... </Style.Triggers> </Style>
The following example defines a MultiTrigger that sets the Foreground property of a ListViewItem to Yellow when the ListViewItem is the selected item and has keyboard focus.
<Style x:Key="MyContainer" TargetType="{x:Type ListViewItem}"> <Setter Property="Margin" Value="0,1,0,0"/> <Setter Property="Height" Value="21"/> <Style.Triggers> ... <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true" /> <Condition Property="Selector.IsSelectionActive" Value="true" /> </MultiTrigger.Conditions> <Setter Property="Foreground" Value="Yellow" /> </MultiTrigger> ... </Style.Triggers> </Style>
For the complete sample, see ListView with Styled ListViewItems Sample.
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.ListViewItem
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.