Skip to content

Latest commit

 

History

History
54 lines (34 loc) · 4.15 KB

listviewitem.md

File metadata and controls

54 lines (34 loc) · 4.15 KB
-api-id -api-type
T:Windows.UI.Xaml.Controls.ListViewItem
winrt class

Windows.UI.Xaml.Controls.ListViewItem

-description

Represents the container for an item in a ListView control.

-xaml-syntax

<ListViewItem .../>
-or-
<ListViewItem ...>
  content
</ListViewItem>

-remarks

The ListViewItem class provides the container for items displayed in a ListView control. You populate the ListView by adding objects directly to its Items collection or by binding its ItemsSource property to a data source. When items are added to the ListView, a ListViewItem container is created automatically for each item in the collection.

You can specify the look of the ListViewItem by setting the ListView's ItemContainerStyle property to a Style with a TargetType of ListViewItem.

Control style and template

You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see Styling controls. The default style, template, and resources that define the look of the control are included in the generic.xaml file. For design purposes, generic.xaml is available locally with the SDK or NuGet package installation.

  • WinUI Styles (recommended): For updated styles from WinUI, see \Users\<username>\.nuget\packages\microsoft.ui.xaml\<version>\lib\uap10.0\Microsoft.UI.Xaml\Themes\generic.xaml.
  • Non-WinUI styles: For built-in styles, see %ProgramFiles(x86)%\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\<SDK version>\Generic\generic.xaml.

Locations might be different if you customized the installation. Styles and resources from different versions of the SDK might have different values.

XAML also includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. Modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the XAML styles article. Light-weight styling resources are available starting in Windows 10, version 1607 (SDK 14393).

Windows 8.1 To assign a custom value based on the data item to the AutomationProperties.Name attached property, you must bind to the item container's Content property. For example, assume you have a Customer data item that has a Name property and you want to use the Customer.Name property as the AutomationProperties.Name value.

In Windows 8, the data item is set as the DataContext of the item container, so you can use a binding like this: AutomationProperties.Name="{Binding Name}".

In Windows 8.1, the item container's DataContext is not set. To bind the AutomationProperties.Name value to the data item's Name property, use a binding like this: AutomationProperties.Name="{Binding Path=Content.Name,RelativeSource={RelativeSource Mode=Self}}".

-examples

-see-also

SelectorItem, ListView, ItemContainerStyle, Item templates for ListView