我正在使用 C# 和 XAML 开发 Windows 10 应用程序.我有一个 ListView,我想更改所选项目的默认 HighLight 颜色.我看到了许多代码示例(例如 this) 但都是为 WP8 或 Win8 设计的,我试图实现这些但它们对我不起作用.
I'm working on a Windows 10 app using C# and XAML. I have a ListView and I want to change the default HighLight color of an selected item. I was seeing many code examples (like this) but all are designed for WP8 or Win8, I was trying to implement those but they do not work for me.
一般来说,我在修改控件的默认主题时遇到了麻烦,因为我找不到有用的文档.如果有人可以帮助我处理高亮颜色并推荐我好的文档,那就太好了.
In general I'm having troubles modifying the default themes of controls because I don't find useful documentation. It would be great if someone can help me with the highlight color and also recommend me good documentation.
实际上发现样式属性的更好方法是使用 Blend.
Actually a better way to discover the styling properties is to use Blend.
首先,在 Blend 中打开您的页面.然后右键单击您的 ListView
并继续
First, open up your page in Blend. Then right click on your ListView
and go
编辑其他模板 > 编辑生成的项目容器 (ItemContainerStyle) > 编辑副本.
给它起个名字然后点击OK.
Give it a name and hit OK.
现在,您已经为 ListViewItem
生成了完整的内置样式,在这里您可以找到有关其外观、动画和其他视觉行为的所有信息.
Now, you have generated the full built-in style for your ListViewItem
s and this is where you can find all the information about their appearance, animations and other visual behaviors.
你应该看看这段代码-
<ListViewItemPresenter CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
ContentMargin="{TemplateBinding Padding}"
CheckMode="Inline"
ContentTransitions="{TemplateBinding ContentTransitions}"
CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
PressedBackground="{ThemeResource SystemControlHighlightListMediumBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="{ThemeResource SystemControlHighlightListLowBrush}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
SelectionCheckMarkVisualEnabled="True"
SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
看到 SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
行了吗?在那里你可以应用你自己的颜色.请记住,它的类型应该是 Brush
而不是 Color
.
See the line SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
? That's where you can apply your own color to it. Keep in mind that it should be of type Brush
instead of Color
.
这篇关于如何更改 UWP 中选定 ListView 项的突出显示颜色(Windows 10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!