Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-use-triggers-to-style-selected-items-in-a-listview.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.7 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Use Triggers to Style Selected Items in a ListView 03/30/2017
ListView controls [WPF], styling
1e2bdce0-afe8-4507-9b18-f33de43de25a

How to: Use Triggers to Style Selected Items in a ListView

This example shows how to define xref:System.Windows.Style.Triggers%2A for a xref:System.Windows.Controls.ListViewItem control so that when a property value of a xref:System.Windows.Controls.ListViewItem changes, the xref:System.Windows.Style of the xref:System.Windows.Controls.ListViewItem changes in response.

Example

If you want the xref:System.Windows.Style of a xref:System.Windows.Controls.ListViewItem to change in response to property changes, define xref:System.Windows.Style.Triggers%2A for the xref:System.Windows.Style change.

The following example defines a xref:System.Windows.Trigger that sets the xref:System.Windows.Controls.Control.Foreground%2A property to xref:System.Windows.Media.Brushes.Blue%2A and changes the xref:System.Windows.FrameworkElement.Cursor%2A to display a xref:System.Windows.Input.CursorType.Hand when the xref:System.Windows.UIElement.IsMouseOver%2A property changes to true.

[!code-xamlListViewChkBox#ListViewItemTriggersStart]
[!code-xamlListViewChkBox#Trigger]
[!code-xamlListViewChkBox#ListViewItemTriggersEnd]

The following example defines a xref:System.Windows.MultiTrigger that sets the xref:System.Windows.Controls.Control.Foreground%2A property of a xref:System.Windows.Controls.ListViewItem to xref:System.Windows.Media.Brushes.Yellow%2A when the xref:System.Windows.Controls.ListViewItem is the selected item and has keyboard focus.

[!code-xamlListViewChkBox#ListViewItemTriggersStart]
[!code-xamlListViewChkBox#MultiTrigger]
[!code-xamlListViewChkBox#ListViewItemTriggersEnd]

See also