如何在开关上改变颜色?

问题描述

我有2个项目。在两个我风格切换。更新VS后,添加新项目时我遇到了问题

  <Switch>
            <visualstatemanager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="On">
                        <VisualState.Setters>
                            <Setter Property="ThumbColor"
                Value="#2D78FD" />
                            <Setter Property="OnColor"
                Value="#2D78FD" />
                        </VisualState.Setters>
                    </VisualState>
                    <VisualState x:Name="Off">
                        <VisualState.Setters>
                            <Setter Property="ThumbColor"
                Value="LightGray" />
                            <Setter Property="OnColor"
                Value="LightGray" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </visualstatemanager.VisualStateGroups>
        </Switch>

我了解自己在主题方面遇到了问题 我的手机上有深色主题,所以我写

BackgroundColor="{AppThemeBinding Light=White,Dark=White}"

然后我有白色BackgroundColor,并且开关有问题 enter image description here

如果我不写

BackgroundColor="{AppThemeBinding Light=White,Dark=White}"

enter image description here

为什么我的OnColor在关闭时不能在白色BackgroundColor上起作用(我尝试了其他颜色,只有ThumbColor更改了颜色)

解决方法

请将您的Xamarin.forms版本更新到最新的4.8.0.1364,我测试了您的代码,它运行良好。