Export (0) Print
Expand All

ListViewItem Class

Represents an item in a ListView control.

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

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

Content Model: ListViewItem is a ContentControl and has one content property, Content. For information about how to set this property, see the Content Control 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 implementing 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.

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.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.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

ADD
Show:
© 2014 Microsoft