DynamicResource 更改 FontSize 和 TextColor 然后保存在 App.Current.Resources

DynamicResource to change FontSize and TextColor then save in App.Current.Resources

使用它来更改 FontSize 并将其保存在 App.Current.Resources 中,有效但不是 FontColor

App.xaml

<Application.Resources>
    <x:Double x:Key="defaultFontSize">14</x:Double>
    <Color x:Key="defaultTextColor">#141000</Color>
    <Style x:Key="ALabel" TargetType="Label">
        <Setter Property="TextColor" Value="{DynamicResource defaultTextColor}" />
        <Setter Property="FontSize" Value="{DynamicResource defaultFontSize}" />
        <Setter Property="HorizontalOptions" Value="Start" />
        <Setter Property="VerticalOptions" Value="Center" />
        <Setter Property="Opacity" Value="0.8" />
    </Style>
</Application.Resources>

MainPage.xaml

<Label
        x:Name="Labeltest3"
        Padding="30,0,30,0"
        Style="{StaticResource ALabel}"
        Text="18" />

MainPage.cs 这适用于 FontSize , Labeltest3.Text 是 18 所以 FontSize = 18

private void Button_Clicked_2(object sender, EventArgs e)
    {
        int value = Convert.ToInt32(Labeltest3.Text);
        Preferences.Set("FontSize", value);
        App.Current.Resources["defaultFontSize"] = Preferences.Get("FontSize", 14);
    }

这不适用于 TextColor,我缺少什么或做错了什么? 在 Label.Text 中用 Hexcode 尝试了各种变体,但没有成功。 不更改 TextColor 且不保存 TextColor

private void Button_Clicked_3(object sender, EventArgs e)
    {
        int value = Convert.ToInt32(Labeltest3.Text);
        Preferences.Set("FontSize", value);
        App.Current.Resources["defaultFontSize"] = Preferences.Get("FontSize", 14);
        Preferences.Set("defaultTextColor", "#ffcc00");
        App.Current.Resources["defaultTextColor"] = Preferences.Get("TextColor", "#141000");
    }

找到了,有效。 改变了这一行 Preferences.Set("defaultTextColor", "#ffcc00");

private void Button_Clicked_3(object sender, EventArgs e)
    {
        Preferences.Set("FontSize", 8);
       App.Current.Resources["defaultFontSize"] = Preferences.Get("FontSize", 14);

        Preferences.Set("TextColor", "#ffcc00");
        App.Current.Resources["defaultTextColor"] = Preferences.Get("TextColor", "#141000");
    }