Skip to content

Commit

Permalink
Make theme selection a combobox (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabboxl committed Aug 2, 2023
1 parent 672f98c commit d535e00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 72 deletions.
75 changes: 13 additions & 62 deletions ClassevivaPCTO/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<helper:EnumToBooleanConverter x:Key="EnumToBooleanConverter" EnumType="ElementTheme" />
</Page.Resources>
<ScrollViewer>
<Grid>
<Grid Padding="0,0,0,128">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -73,78 +73,29 @@
x:Uid="Settings_Personalization" />


<labs:SettingsExpander x:Uid="SettingsExpanderTheme">
<labs:SettingsExpander.HeaderIcon>
<labs:SettingsCard x:Uid="SettingsExpanderTheme">
<labs:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE790;" />
</labs:SettingsExpander.HeaderIcon>

<labs:SettingsExpander.Items>
<labs:SettingsCard Header="Scegli un tema:">
<StackPanel>
<RadioButton
x:Uid="Settings_Theme_Light"
Checked="ThemeChanged_CheckedAsync"
IsChecked="{x:Bind ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Light, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Light</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
x:Uid="Settings_Theme_Dark"
Checked="ThemeChanged_CheckedAsync"
IsChecked="{x:Bind ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Dark, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Dark</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
x:Uid="Settings_Theme_Default"
Checked="ThemeChanged_CheckedAsync"
IsChecked="{x:Bind ElementTheme, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Default, Mode=OneWay}"
FontSize="15"
GroupName="AppTheme">
<RadioButton.CommandParameter>
<xaml:ElementTheme>Default</xaml:ElementTheme>
</RadioButton.CommandParameter>
</RadioButton>
</StackPanel>
</labs:SettingsCard>
</labs:SettingsCard.HeaderIcon>

</labs:SettingsExpander.Items>
</labs:SettingsExpander>
<!-- the combobox selected index is bound to the current theme enum value -->

<!--
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
Text="Sezione 2" />
<labs:SettingsCard Description="Another card to show grouping of cards"
Header="Another SettingsCard">
<labs:SettingsCard.HeaderIcon>
<FontIcon Glyph="&#xE799;" />
</labs:SettingsCard.HeaderIcon>
<ComboBox SelectedIndex="0" >
<ComboBox SelectedIndex="{x:Bind ElementTheme.GetHashCode()}"
SelectionChanged="ThemeSelector_OnSelectionChanged">
<ComboBoxItem
x:Uid="Settings_Theme_Light"
>
x:Uid="Settings_Theme_Default">

</ComboBoxItem>
<ComboBoxItem
x:Uid="Settings_Theme_Dark"
>
x:Uid="Settings_Theme_Light">

</ComboBoxItem>
<ComboBoxItem
x:Uid="Settings_Theme_Default"
>
x:Uid="Settings_Theme_Dark">

</ComboBoxItem>
</ComboBox>
</labs:SettingsCard>
-->


<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
Expand Down
19 changes: 9 additions & 10 deletions ClassevivaPCTO/Views/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ private string GetVersionDescription()
return $"{version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
}

private async void ThemeChanged_CheckedAsync(object sender, RoutedEventArgs e)
{
var param = (sender as RadioButton)?.CommandParameter;

if (param != null)
{
await ThemeSelectorService.SetThemeAsync((ElementTheme)param);
}
}

public event PropertyChangedEventHandler PropertyChanged;

private void Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
Expand Down Expand Up @@ -140,5 +130,14 @@ private async void ButtonChangelog_OnClick(object sender, RoutedEventArgs e)
var dialog = new WhatsNewDialog();
await dialog.ShowAsync();
}

private async void ThemeSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox themeSelector = (ComboBox) sender;

//change theme based on selected index of the combobox sender
await ThemeSelectorService.SetThemeAsync((ElementTheme)themeSelector.SelectedIndex);

}
}
}

0 comments on commit d535e00

Please sign in to comment.