用它来改变字体大小并保存在App.Current.Resources, works中,但不包括字体颜色
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这适用于字体大小,Labeltest3。Text = 18所以font = 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,我错过了什么或做错了?在标签中尝试了所有类型的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");
}