项目的突出显示颜色

项目的突出显示颜色

本文介绍了如何在 UWP (Windows 10) 中更改所选 ListView 项目的突出显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C# 和 XAML 开发 Windows 10 应用程序.我有一个 ListView,我想更改所选项目的默认高亮颜色.我看到了许多代码示例(例如 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) > 编辑副本.

为其命名并点击确定.

现在,您已经为 ListViewItem 生成了完整的内置样式,您可以在此处找到有关它们的外观、动画和其他视觉行为的所有信息.

Now, you have generated the full built-in style for your ListViewItems and this is where you can find all the information about their appearance, animations and other visual behaviors.

你应该看看这段代码 -

You should be look at this piece of code -

<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 (Windows 10) 中更改所选 ListView 项目的突出显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:18