[Settings] Using SettingsControls (#1964)

* Adding SettingsControls package

* Using new SettingsControls

* Tweaks

* Version bump

* Replacing Button with HyperlinkButton per design spec

* Update Settings.xaml

* Fix top spacing
This commit is contained in:
Niels Laute 2023-03-16 11:06:40 +01:00 committed by GitHub
commit 47f314bb10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 123 additions and 184 deletions

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<packageSources> <packageSources>
<clear /> <clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="Toolkit Labs" value="https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json" />
</packageSources> </packageSources>
<disabledPackageSources> <disabledPackageSources>
<clear /> <clear />

View file

@ -791,6 +791,9 @@
</Page> </Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Labs.Uwp.SettingsControls">
<Version>0.0.16</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.14</Version> <Version>6.2.14</Version>
</PackageReference> </PackageReference>

View file

@ -4706,11 +4706,11 @@
<value>Appearance</value> <value>Appearance</value>
<comment>Subtitle of appearance setting on Settings page</comment> <comment>Subtitle of appearance setting on Settings page</comment>
</data> </data>
<data name="SettingsAppThemeTitle.Text" xml:space="preserve"> <data name="AppThemeExpander.Header" xml:space="preserve">
<value>App theme</value> <value>App theme</value>
<comment>Title of App theme expander</comment> <comment>Title of App theme expander</comment>
</data> </data>
<data name="SettingsAppThemeDescription.Text" xml:space="preserve"> <data name="AppThemeExpander.Description" xml:space="preserve">
<value>Select which app theme to display</value> <value>Select which app theme to display</value>
<comment>Description of App theme expander</comment> <comment>Description of App theme expander</comment>
</data> </data>

View file

@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:automation="using:CalculatorApp.ViewModel.Common.Automation" xmlns:automation="using:CalculatorApp.ViewModel.Common.Automation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
Loaded="OnLoaded" Loaded="OnLoaded"
@ -13,7 +14,7 @@
<ResourceDictionary> <ResourceDictionary>
<Style x:Key="SettingsContentScrollViewStyle" TargetType="ScrollViewer"> <Style x:Key="SettingsContentScrollViewStyle" TargetType="ScrollViewer">
<Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Top"/> <Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/> <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="HorizontalScrollMode" Value="Disabled"/> <Setter Property="HorizontalScrollMode" Value="Disabled"/>
<Setter Property="IsHorizontalRailEnabled" Value="False"/> <Setter Property="IsHorizontalRailEnabled" Value="False"/>
@ -30,11 +31,19 @@
<Setter Property="TextWrapping" Value="Wrap"/> <Setter Property="TextWrapping" Value="Wrap"/>
</Style> </Style>
<Style x:Key="SettingsCategoryTitleTextBlockStyle"
BasedOn="{StaticResource BodyStrongTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="Margin" Value="0,29,0,5"/>
</Style>
<automation:NarratorNotifier x:Name="NarratorNotifier"/> <automation:NarratorNotifier x:Name="NarratorNotifier"/>
<!-- Override default hyperlink button background color --> <!-- Override default hyperlink button background color -->
<StaticResource x:Key="HyperlinkButtonBackgroundPointerOver" ResourceKey="SubtleFillColorTransparentBrush"/> <StaticResource x:Key="HyperlinkButtonBackgroundPointerOver" ResourceKey="SubtleFillColorTransparentBrush"/>
<StaticResource x:Key="HyperlinkButtonBackgroundPressed" ResourceKey="SubtleFillColorTransparentBrush"/> <StaticResource x:Key="HyperlinkButtonBackgroundPressed" ResourceKey="SubtleFillColorTransparentBrush"/>
<x:Double x:Key="SettingsCardSpacing">3</x:Double>
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
@ -43,42 +52,6 @@
<RowDefinition Height="{x:Bind TitleBarHeight, Mode=OneWay}"/> <RowDefinition Height="{x:Bind TitleBarHeight, Mode=OneWay}"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LayoutVisualStates">
<VisualState x:Name="LargeWideView">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight="0" MinWindowWidth="690"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ColumnAbout.Width" Value="324"/>
<Setter Target="AboutContentGrid.(Grid.Row)" Value="0"/>
<Setter Target="AboutContentGrid.(Grid.RowSpan)" Value="3"/>
<Setter Target="AboutContentGrid.(Grid.Column)" Value="1"/>
<Setter Target="AboutGroupTitle.Margin" Value="0"/>
<Setter Target="AboutContentGrid.Margin" Value="60,0,0,0"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="SideVisible">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight="0" MinWindowWidth="632"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="ColumnMain.Width" Value="*"/>
<Setter Target="ColumnAbout.Width" Value="*"/>
<Setter Target="AboutContentGrid.(Grid.Row)" Value="0"/>
<Setter Target="AboutContentGrid.(Grid.RowSpan)" Value="3"/>
<Setter Target="AboutContentGrid.(Grid.Column)" Value="1"/>
<Setter Target="AboutGroupTitle.Margin" Value="0"/>
<Setter Target="AboutContentGrid.Margin" Value="60,0,0,0"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="DefaultLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight="0" MinWindowWidth="0"/>
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Button x:Name="BackButton" <Button x:Name="BackButton"
x:Uid="TitleBarBackButton" x:Uid="TitleBarBackButton"
@ -103,158 +76,120 @@
</Grid> </Grid>
<ScrollViewer Grid.Row="1" <ScrollViewer Grid.Row="1"
Margin="0,60,0,0" Margin="0,30,0,0"
Padding="24,0,24,16" Padding="24,0,24,16"
Style="{StaticResource SettingsContentScrollViewStyle}"> Style="{StaticResource SettingsContentScrollViewStyle}">
<Grid x:Name="ContentGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnMain" Width="*"/>
<ColumnDefinition x:Name="ColumnAbout" Width="0"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="AppearanceTitleRow" Height="Auto"/>
<RowDefinition x:Name="AppearanceExpanderRow" Height="Auto"/>
<RowDefinition x:Name="AboutTitleContentRow" Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Spacing="{StaticResource SettingsCardSpacing}">
<StackPanel.ChildrenTransitions>
<EntranceThemeTransition FromVerticalOffset="50" IsStaggeringEnabled="True"/>
<RepositionThemeTransition IsStaggeringEnabled="False"/>
</StackPanel.ChildrenTransitions>
<TextBlock x:Uid="SettingsAppearance" <TextBlock x:Uid="SettingsAppearance"
Style="{StaticResource BodyStrongTextBlockStyle}" Style="{StaticResource SettingsCategoryTitleTextBlockStyle}"
AutomationProperties.HeadingLevel="Level1"/> AutomationProperties.HeadingLevel="Level1"/>
<labs:SettingsExpander x:Name="AppThemeExpander"
Description="Select which app theme to display"
Header="App theme">
<labs:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xE790;"/>
</labs:SettingsExpander.HeaderIcon>
<labs:SettingsExpander.Items>
<labs:SettingsCard ContentAlignment="Left">
<muxc:RadioButtons x:Name="ThemeRadioButtons"
Margin="0,-8,0,0"
SelectionChanged="OnThemeSelectionChanged">
<RadioButton x:Name="LightThemeRadioButton"
x:Uid="LightThemeRadioButton"
Tag="Light"/>
<RadioButton x:Name="DarkThemeRadioButton"
x:Uid="DarkThemeRadioButton"
Tag="Dark"/>
<RadioButton x:Name="SystemThemeRadioButton"
x:Uid="SystemThemeRadioButton"
Tag="Default"/>
</muxc:RadioButtons>
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
<muxc:Expander x:Name="AppThemeExpander" <TextBlock x:Name="AboutGroupTitle"
x:Uid="AppThemeExpander" x:Uid="AboutGroupTitle"
Grid.Row="1" Style="{ThemeResource SettingsCategoryTitleTextBlockStyle}"
Margin="0,8,0,0" AutomationProperties.HeadingLevel="Level1"/>
HorizontalAlignment="Stretch" <labs:SettingsExpander x:Name="AboutExpander">
VerticalAlignment="Top" <labs:SettingsExpander.HeaderIcon>
HorizontalContentAlignment="Left" <BitmapIcon AutomationProperties.AccessibilityView="Raw" UriSource="ms-appx:///Assets/CalculatorAppList.png"/>
ExpandDirection="Down" </labs:SettingsExpander.HeaderIcon>
IsExpanded="False"> <TextBlock x:Name="AboutBuildVersion"
<muxc:Expander.Header> Foreground="{ThemeResource TextFillColorSecondaryBrush}"
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Center"> IsTextSelectionEnabled="True"/>
<Grid.ColumnDefinitions> <labs:SettingsExpander.Items>
<ColumnDefinition Width="Auto"/> <labs:SettingsCard ContentAlignment="Left">
<ColumnDefinition Width="*"/> <StackPanel Margin="0,4,0,6"
</Grid.ColumnDefinitions> Orientation="Vertical"
Spacing="12">
<FontIcon Margin="0,0,12,0" <HyperlinkButton x:Name="AboutEULA"
VerticalAlignment="Center" Padding="0"
Foreground="{ThemeResource TextFillColorPrimaryBrush}" NavigateUri="https://go.microsoft.com/fwlink/?LinkID=529064"
FontFamily="{ThemeResource CalculatorFontFamily}" ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?LinkID=529064">
FontSize="16" <TextBlock x:Uid="AboutEULA"
Glyph="&#xE790;"/> FontSize="{ThemeResource BodyFontSize}"
TextWrapping="Wrap"/>
</HyperlinkButton>
<StackPanel Grid.Column="1" <HyperlinkButton x:Name="AboutControlServicesAgreement"
Margin="0,12" Padding="0"
Orientation="Vertical"> NavigateUri="https://go.microsoft.com/fwlink/?LinkID=822631"
<TextBlock x:Uid="SettingsAppThemeTitle" Style="{StaticResource BodyTextBlockStyle}"/> ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?LinkID=822631">
<TextBlock x:Uid="SettingsAppThemeDescription" <TextBlock x:Uid="AboutControlServicesAgreement"
Style="{StaticResource CaptionTextBlockStyle}" FontSize="{ThemeResource BodyFontSize}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}" TextWrapping="Wrap"/>
TextWrapping="WrapWholeWords"/> </HyperlinkButton>
<HyperlinkButton x:Name="AboutControlPrivacyStatement"
Padding="0"
NavigateUri="https://go.microsoft.com/fwlink/?LinkID=521839"
ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?LinkID=521839">
<TextBlock x:Uid="AboutControlPrivacyStatement"
FontSize="{ThemeResource BodyFontSize}"
TextWrapping="Wrap"/>
</HyperlinkButton>
</StackPanel> </StackPanel>
</Grid> </labs:SettingsCard>
</muxc:Expander.Header> </labs:SettingsExpander.Items>
<muxc:Expander.Content> </labs:SettingsExpander>
<muxc:RadioButtons x:Name="ThemeRadioButtons"
Margin="32,0,0,0"
SelectionChanged="OnThemeSelectionChanged">
<RadioButton x:Name="LightThemeRadioButton"
x:Uid="LightThemeRadioButton"
Tag="Light"/>
<RadioButton x:Name="DarkThemeRadioButton"
x:Uid="DarkThemeRadioButton"
Tag="Dark"/>
<RadioButton x:Name="SystemThemeRadioButton"
x:Uid="SystemThemeRadioButton"
Tag="Default"/>
</muxc:RadioButtons>
</muxc:Expander.Content>
</muxc:Expander>
<Grid x:Name="AboutContentGrid" Grid.Row="2"> <HyperlinkButton x:Name="FeedbackButton"
<Grid.RowDefinitions> x:Uid="FeedbackButton"
<RowDefinition Height="Auto"/> MinWidth="120"
<RowDefinition Height="Auto"/> Margin="-12,4,0,0"
<RowDefinition Height="Auto"/> HorizontalAlignment="Left"
</Grid.RowDefinitions> VerticalAlignment="Top"
FontSize="{StaticResource BodyFontSize}"
Click="FeedbackButton_Click"/>
<TextBlock x:Name="AboutGroupTitle" <RichTextBlock x:Name="AboutContribute"
x:Uid="AboutGroupTitle" Grid.Row="2"
Margin="0,20,0,0" Margin="1,9,0,0"
Style="{ThemeResource BodyStrongTextBlockStyle}" Style="{StaticResource SettingsRichTextBlockStyle}">
AutomationProperties.HeadingLevel="Level1"/> <Paragraph>
<StackPanel Grid.Row="1" <!--
Margin="0,8,0,0" Note: don't put Hyperlink element start to the next line
Orientation="Vertical"> otherwise unexpected whitespace will be add.
<RichTextBlock x:Name="AboutContentBody" Style="{StaticResource SettingsRichTextBlockStyle}"> -->
<Paragraph> <Run x:Name="ContributeRunBeforeLink"/><Hyperlink Foreground="{x:Bind AboutEULA.Foreground, Mode=OneWay}"
<Run x:Name="AboutBuildVersion"/> NavigateUri="https://go.microsoft.com/fwlink/?linkid=2099939"
<LineBreak/> TextDecorations="None"
<Run x:Name="AboutControlCopyrightRun"/> ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?linkid=2099939"
</Paragraph> UnderlineStyle="None">
</RichTextBlock> <Run x:Name="ContributeRunLink"/>
</Hyperlink><Run x:Name="ContributeRunAfterLink"/>
</Paragraph>
</RichTextBlock>
<HyperlinkButton x:Name="AboutEULA" </StackPanel>
Margin="0,16,0,0"
Padding="0"
NavigateUri="https://go.microsoft.com/fwlink/?LinkID=529064"
ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?LinkID=529064">
<TextBlock x:Uid="AboutEULA"
FontSize="{ThemeResource BodyFontSize}"
TextWrapping="Wrap"/>
</HyperlinkButton>
<HyperlinkButton x:Name="AboutControlServicesAgreement"
Margin="0,16,0,0"
Padding="0"
NavigateUri="https://go.microsoft.com/fwlink/?LinkID=822631"
ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?LinkID=822631">
<TextBlock x:Uid="AboutControlServicesAgreement"
FontSize="{ThemeResource BodyFontSize}"
TextWrapping="Wrap"/>
</HyperlinkButton>
<HyperlinkButton x:Name="AboutControlPrivacyStatement"
Margin="0,16,0,0"
Padding="0"
NavigateUri="https://go.microsoft.com/fwlink/?LinkID=521839"
ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?LinkID=521839">
<TextBlock x:Uid="AboutControlPrivacyStatement"
FontSize="{ThemeResource BodyFontSize}"
TextWrapping="Wrap"/>
</HyperlinkButton>
<Button x:Name="FeedbackButton"
x:Uid="FeedbackButton"
MinWidth="120"
Margin="0,24,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
FontSize="{StaticResource BodyFontSize}"
Click="FeedbackButton_Click"/>
</StackPanel>
<RichTextBlock x:Name="AboutContribute"
Grid.Row="2"
Margin="0,16,0,0"
Style="{StaticResource SettingsRichTextBlockStyle}">
<Paragraph>
<!--
Note: don't put Hyperlink element start to the next line
otherwise unexpected whitespace will be add.
-->
<Run x:Name="ContributeRunBeforeLink"/><Hyperlink Foreground="{x:Bind AboutEULA.Foreground, Mode=OneWay}"
NavigateUri="https://go.microsoft.com/fwlink/?linkid=2099939"
TextDecorations="None"
ToolTipService.ToolTip="https://go.microsoft.com/fwlink/?linkid=2099939"
UnderlineStyle="None">
<Run x:Name="ContributeRunLink"/>
</Hyperlink><Run x:Name="ContributeRunAfterLink"/>
</Paragraph>
</RichTextBlock>
</Grid>
</Grid>
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
</UserControl> </UserControl>

View file

@ -45,7 +45,7 @@ namespace CalculatorApp
var copyrightText = var copyrightText =
LocalizationStringUtil.GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright"), BUILD_YEAR); LocalizationStringUtil.GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright"), BUILD_YEAR);
AboutControlCopyrightRun.Text = copyrightText; AboutExpander.Description = copyrightText;
InitializeContributeTextBlock(); InitializeContributeTextBlock();
} }
@ -108,8 +108,8 @@ namespace CalculatorApp
private void SetVersionString() private void SetVersionString()
{ {
PackageVersion version = Package.Current.Id.Version; PackageVersion version = Package.Current.Id.Version;
string appName = AppResourceProvider.GetInstance().GetResourceString("AppName"); AboutExpander.Header = AppResourceProvider.GetInstance().GetResourceString("AppName");
AboutBuildVersion.Text = appName + " " + version.Major + "." + version.Minor + "." + version.Build + "." + version.Revision; AboutBuildVersion.Text = version.Major + "." + version.Minor + "." + version.Build + "." + version.Revision;
} }
private void InitializeContributeTextBlock() private void InitializeContributeTextBlock()