.NET MAUI 条目控件禁用时的颜色

问题描述 投票:0回答:1

在 Android 14(及更早版本)的深色主题中,Entry 控件中的文本已通过 IsEnabled = False 禁用,颜色为灰色。这在黑色背景下很难阅读。我还没有找到在禁用状态下访问此颜色的方法。如果不在 XAML 中,是否可以通过编程方式更改此设置?

<Entry x:Name="TextEditor"
    IsEnabled="False"
    Keyboard="Plain"
    TextTransform="Uppercase"
    MinimumWidthRequest="140"
    MaxLength="12"
    ReturnType="Next"
    Text="{Binding SomeVar}"/>

我已经使用了 AppThemeBinding,但似乎没有一个可以应用它的 Entry 属性。

我尝试更改 TextColor 属性以使用默认值以外的其他颜色,希望当 IsEnabled 设置为 false 时使用的颜色将是 TextColor 的某种派生,但事实并非如此。

c# .net xaml maui
1个回答
0
投票

事实证明有一个 VisualState 正在执行此操作,因此我可以毫无问题地对其进行编辑。

            <VisualStateGroupList>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="Disabled">
                        <VisualState.Setters>
                            <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray300}, Dark={StaticResource Gray600}}" />
                        </VisualState.Setters>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateGroupList>

© www.soinside.com 2019 - 2024. All rights reserved.