如何修改MAUI中Slider的悬停颜色?
MAUI Slider悬停已走过轨道颜色修改方案
我正在开发一款功能增强型音频播放器,Slider是UI核心组件。但无法修改Slider悬停时已走过轨道的颜色(因色盲推测为蓝色)。
尝试过的无效方案
全局样式表重写VisualState
在全局样式中重写Slider所有状态属性,无效果:
<Style TargetType="Slider"> <Setter Property="VisualStateManager.VisualStateGroups"> <VisualStateGroupList> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"> <VisualState.Setters> <Setter Property="BackgroundColor" Value="Red" /> <Setter Property="MinimumTrackColor" Value="Red" /> <Setter Property="MaximumTrackColor" Value="Red" /> <Setter Property="ThumbColor" Value="Red" /> </VisualState.Setters> </VisualState> <VisualState x:Name="PointerOver"> <VisualState.Setters> <Setter Property="BackgroundColor" Value="Red" /> <Setter Property="MinimumTrackColor" Value="Red" /> <Setter Property="MaximumTrackColor" Value="Red" /> <Setter Property="ThumbColor" Value="Red" /> </VisualState.Setters> </VisualState> <VisualState x:Name="Selected"> <VisualState.Setters> <Setter Property="BackgroundColor" Value="Red" /> <Setter Property="MinimumTrackColor" Value="Red" /> <Setter Property="MaximumTrackColor" Value="Red" /> <Setter Property="ThumbColor" Value="Red" /> </VisualState.Setters> </VisualState> <VisualState x:Name="Focused"> <VisualState.Setters> <Setter Property="BackgroundColor" Value="Red" /> <Setter Property="MinimumTrackColor" Value="Red" /> <Setter Property="MaximumTrackColor" Value="Red" /> <Setter Property="ThumbColor" Value="Red" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateGroupList> </Setter> </Style>
Windows平台App.xaml重写WinUI Slider属性
在Platform\Windows\app.xaml中重写WinUI的Slider属性,同样无效:
<maui:MauiWinUIApplication x:Class="MPC.MForms.WinUI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:maui="using:Microsoft.Maui" xmlns:local="using:MPC.MForms.WinUI"> <maui:MauiWinUIApplication.Resources> <Style TargetType="Slider"> <Setter Property="BorderBrush" Value="Red"/> <Setter Property="Background" Value="Red"/> <Setter Property="Foreground" Value="Red"/> <Setter Property="FocusVisualPrimaryBrush" Value="Red"/> <Setter Property="FocusVisualSecondaryBrush" Value="Red"/> </Style> </maui:MauiWinUIApplication.Resources> </maui:MauiWinUIApplication>
有效解决方案
在Platforms\Windows\App.xaml文件中,通过重写WinUI的SliderTrackValueFillPointerOver颜色资源,即可修改Slider悬停时已走过轨道的颜色:
<maui:MauiWinUIApplication.Resources> <Color x:Key="SliderTrackValueFillPointerOver">Red</Color> </maui:MauiWinUIApplication.Resources>
内容的提问来源于stack exchange,提问作者Olograph
相关产品推荐
相关产品推荐

