Hello, I want to set Font attributes and Font size when button is clicked and restore font attributes,size other button in layout to default, but after changing font size or attributes, family setting to default, and after this font family I can`t change.
First use of set font (worked):
public Schedule()
{
.....
foreach (Button day in slWeek.Children)
{
Device.OnPlatform(iOS: () => { day.FontFamily = "NotoSerif-Regular"; },
Android: () => { CustomFontEffect.SetFontFileName(day, "NotoSerif-Regular"); },
WinPhone: () => { day.FontFamily = "/Assets/Fonts/NotoSerif-Regular.ttf#NotoSerif-Regular"; }
);
day.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Button));
day.FontAttributes = FontAttributes.None;
....
event of click:
private void BtnWeek_Clicked(object sender, EventArgs e)
{
var btn = (sender as Button);
foreach (Button day in slWeek.Children)
{
if (day.BackgroundColor == Color.Gray)
{
day.FontAttributes = FontAttributes.None;
day.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Button));
day.BackgroundColor = Color.FromRgba(204, 204, 204, 255);
}
}
btn.FontAttributes = FontAttributes.Bold;
btn.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button));
btn.BackgroundColor = Color.Gray;
}
XAML Definition
<StackLayout x:Name="slWeek" Orientation="Horizontal" HeightRequest="50" BackgroundColor="Gray" Spacing="0" Padding="0,0,0,0" Margin="0,0,0,0">
<Button Style="{StaticResource buttonWeekStyle}" Clicked="BtnWeek_Clicked" Text="{l10n:Translate Monday}"></Button>
<Button Style="{StaticResource buttonWeekStyle}" Clicked="BtnWeek_Clicked" Text="{l10n:Translate Tuesday}"></Button>
<Button Style="{StaticResource buttonWeekStyle}" Clicked="BtnWeek_Clicked" Text="{l10n:Translate Wednesday}"></Button>
<Button Style="{StaticResource buttonWeekStyle}" Clicked ="BtnWeek_Clicked" Text="{l10n:Translate Thursday}"></Button>
<Button Style="{StaticResource buttonWeekStyle}" Clicked ="BtnWeek_Clicked" Text="{l10n:Translate Friday}"></Button>
<Button Style="{StaticResource buttonWeekStyle}" Clicked ="BtnWeek_Clicked" Text="{l10n:Translate Saturday}"></Button>
<Button Style="{StaticResource buttonWeekStyle}" Clicked ="BtnWeek_Clicked" Text="{l10n:Translate Sanday}"></Button>
</StackLayout>
XAML Style
<Style x:Key="buttonWeekStyle" TargetType="Button">
<Setter Property="BackgroundColor" Value="#CCCCCC" />
<Setter Property="Margin" Value="-5,-10,0,-10"></Setter>
<Setter Property="HorizontalOptions" Value="Fill"></Setter>
</Style>
Example:
After loading page:
When I click on button:
After click on other button:
(see different Monday and Tuesday)
I tried to set Font Family after click but nothing has changed
P.S. Sorry for my English