如何禁用UWP ListView控件的ListViewItem reveal效果(常规修改资源无效)
关闭UWP ListView控件Reveal效果的实现方法
为什么之前修改资源没有生效
你之前调整的ListViewItemBackground系列Brush仅对应控件的静态背景填充层,而Reveal是系统叠加在控件背景之上的独立光效渲染层,会覆盖基础背景的视觉表现,因此单独修改这类Brush无法达到关闭Reveal的效果。
单控件精准关闭(仅针对指定ListView)
直接在对应ListView的ItemContainerStyle中完成两项核心配置,适合不需要全局调整的场景:
- 将
ListViewItem的RevealBackgroundShowsAboveContent属性设为False,直接阻断Reveal层在内容上方的渲染 - 替换Reveal特效实际读取的关联资源,清空残留的光效表现
示例代码:
<ListView> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="RevealBackgroundShowsAboveContent" Value="False"/> <Setter Property="Resources"> <Setter.Value> <ResourceDictionary> <!-- 自定义静态背景,替换之前的纯色配置 --> <SolidColorBrush x:Key="ListViewItemBackground" Color="Red" /> <SolidColorBrush x:Key="ListViewItemBackgroundPointerOver" Color="Red" /> <SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="Red" /> <SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="Red" /> <!-- 清空Reveal关联的光效层,避免残留高亮、描边、投影效果 --> <SolidColorBrush x:Key="ListViewItemTargetBackground" Color="Transparent" /> <SolidColorBrush x:Key="ListViewItemTargetBackgroundPointerOver" Color="Transparent" /> <SolidColorBrush x:Key="ListViewItemTargetBackgroundSelected" Color="Transparent" /> <SolidColorBrush x:Key="ListViewItemTargetBackgroundSelectedPointerOver" Color="Transparent" /> </ResourceDictionary> </Setter.Value> </Setter> </Style> </ListView.ItemContainerStyle> </ListView>
全局关闭所有控件的Reveal效果
如果需要统一移除全应用范围内所有控件的Reveal特效,不需要逐个修改控件配置,直接在App.xaml的应用级资源中添加以下配置即可:
<Application.Resources> <ResourceDictionary> <!-- 从渲染源头关闭Reveal特效 --> <SolidColorBrush x:Key="RevealBackgroundBrush" Color="Transparent" /> <SolidColorBrush x:Key="RevealBorderBrush" Color="Transparent" /> </ResourceDictionary> </Application.Resources>
常见注意事项
RevealBackgroundShowsAboveContent是ListViewItem的原生依赖属性,必须通过样式Setter赋值才能生效,仅在控件资源中修改Brush无法触发这个阻断逻辑- 完成上述配置后,你自定义的静态背景色不会再被Reveal的叠加光效遮挡,所有状态的视觉表现都会和你设置的纯色Brush保持一致
内容的提问来源于stack exchange,提问作者AtosNicoS
相关产品推荐
相关产品推荐

