如何更改选定的ListView项的高亮颜色在UWP(窗10) [英] How to change Highlight color of the selected ListView item in UWP (Windows 10)

查看:443
本文介绍了如何更改选定的ListView项的高亮颜色在UWP(窗10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#和XAML在Windows 10应用程序的工作。
我有一个ListView,我想更改选定项的默认高亮颜色。我看到很多code例子(像<一个href=\"http://stackoverflow.com/questions/25596398/how-to-change-color-of-the-selected-listview-item-wp8-1\">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.

推荐答案

其实有更好的方式来发现样式属性是使用混合。

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)>编辑复制

给它一个名称和命中的确定

Give it a name and hit OK.

现在,已生成的全内置样式为你的 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.

您应该看看这片code的 -

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}?这就是你可以将自己的颜色吧。请记住,它应该是类型而不是颜色

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.

这篇关于如何更改选定的ListView项的高亮颜色在UWP(窗10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆