Use this to change the FontSize and save it in App.Current.Resources , works but not the 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 This works for FontSize , Labeltest3.Text is 18 so 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);
}
This is not working for TextColor , what am i missing or doing wrong ? Tryed all kinds of variations with the Hexcode in a Label.Text but no luck. Not Changing of the TextColor and no saving of the 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");
}
CodePudding user response:
Found it, this works. Changed this line 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");
}