uwp win10 Listview SelectedItem样式 [英] uwp win10 Listview SelectedItem Style
问题描述
选中此列表后,是否可以更改ListviewItem的属性?
Is there a way to change the properties of a ListviewItem when this one is selected?
例如,我希望ListviewItem内的矩形为红色
As an example, I want that a rectangle inside the ListviewItem to be Red when selected and Blue by default.
如何以优雅的方式实现这一目标?
How to achieve this in an elegant manner?
推荐答案
您可以设置 ListView.ItemContainerStyle
自定义<$ c $中使用的 ListViewItems
的样式$ c> ListView 。
You can set ListView.ItemContainerStyle
to customize the style of ListViewItems
used in the ListView
.
此页面显示默认样式: https://msdn.microsoft.com/zh-CN/library/windows/apps/mt299136.aspx
This page shows the default style: https://msdn.microsoft.com/en-us/library/windows/apps/mt299136.aspx
在您的示例中,您将使用以下代码更改 Selected〜Background
属性:
In case of your example - you would change the Selected~Background
properties in code similar to below:
<ListView ...>
<ListView.ItemContainerStyle>
<Style
TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
ContentTransitions="{TemplateBinding ContentTransitions}"
SelectionCheckMarkVisualEnabled="True"
CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
ContentMargin="{TemplateBinding Padding}"
CheckMode="Inline"/>
</ControlTemplate>
这篇关于uwp win10 Listview SelectedItem样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!