Skip to content

Commit

Permalink
make theme/orientation settings work and use local settings store
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertK66 committed Aug 24, 2023
1 parent 19655fb commit 128c406
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 119 deletions.
13 changes: 12 additions & 1 deletion MyHomeAudio/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel;
Expand Down Expand Up @@ -46,7 +47,10 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
m_window.Activate();
}

private Window m_window;
public MainWindow m_window;


public new static App Current => (App)Application.Current;

public static string WinAppSdkDetails {
get => string.Format("Windows App SDK {0}.{1}.{2}{3}",
Expand All @@ -60,5 +64,12 @@ public static string WinAppSdkRuntimeDetails {
}
}

public static TEnum GetEnum<TEnum>(string text) where TEnum : struct {
if (!typeof(TEnum).GetTypeInfo().IsEnum) {
throw new InvalidOperationException("Generic parameter 'TEnum' must be an enum.");
}
return (TEnum)Enum.Parse(typeof(TEnum), text);
}

}
}
13 changes: 13 additions & 0 deletions MyHomeAudio/AppSettingKeys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyHomeAudio {
internal class AppSettingKeys {
internal const String IsLeftMode = "NavView_IsLeftMode";

internal const String UiTheme = "App_Theme";
}
}
40 changes: 21 additions & 19 deletions MyHomeAudio/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<NavigationView ItemInvoked="NavigationView_ItemInvoked" IsBackButtonVisible="Collapsed" Header="This is Header Text" >
<NavigationView.MenuItems>
<NavigationViewItem Icon="Play" Content="Menu Item1" Tag="SamplePage1" />
<NavigationViewItem Icon="Save" Content="Menu Item2" Tag="SamplePage2" >
<NavigationViewItem.MenuItems>
<NavigationViewItem Content="Mail" Icon="Mail" Tag="SamplePage2.1"/>
<NavigationViewItem Content="Calendar" Icon="Calendar" Tag="SamplePage2.2">
<NavigationViewItem.MenuItems>
<NavigationViewItem Content="Mail" Icon="Manage" Tag="SamplePage2.2.1"/>
<NavigationViewItem Content="Calendar" Icon="Camera" Tag="SamplePage2.2.2"/>
</NavigationViewItem.MenuItems>
</NavigationViewItem>
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<NavigationViewItem Icon="Refresh" Content="Menu Item3" Tag="SamplePage3" />
<NavigationViewItem Icon="Download" Content="Menu Item4" Tag="SamplePage4" />
</NavigationView.MenuItems>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<NavigationView x:Name="MainNavView" ItemInvoked="NavigationView_ItemInvoked" IsBackButtonVisible="Collapsed" Header="This is Header Text">
<NavigationView.MenuItems>
<NavigationViewItem Icon="Play" Content="Menu Item1" Tag="SamplePage1" />
<NavigationViewItem Icon="Save" Content="Menu Item2" Tag="SamplePage2" >
<NavigationViewItem.MenuItems>
<NavigationViewItem Content="Mail" Icon="Mail" Tag="SamplePage2.1"/>
<NavigationViewItem Content="Calendar" Icon="Calendar" Tag="SamplePage2.2">
<NavigationViewItem.MenuItems>
<NavigationViewItem Content="Mail" Icon="Manage" Tag="SamplePage2.2.1"/>
<NavigationViewItem Content="Calendar" Icon="Camera" Tag="SamplePage2.2.2"/>
</NavigationViewItem.MenuItems>
</NavigationViewItem>
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<NavigationViewItem Icon="Refresh" Content="Menu Item3" Tag="SamplePage3" />
<NavigationViewItem Icon="Download" Content="Menu Item4" Tag="SamplePage4" />
</NavigationView.MenuItems>

<Frame x:Name="ContentFrame" />
<Frame x:Name="ContentFrame" />

</NavigationView>
</NavigationView>
</Grid>
</Window>
30 changes: 23 additions & 7 deletions MyHomeAudio/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Windows.UI;
using System.Net.NetworkInformation;
using MyHomeAudio.pages;
using Windows.Storage;

//using AppUIBasics.Common;
//using AppUIBasics.Data;
Expand Down Expand Up @@ -45,31 +46,46 @@ namespace MyHomeAudio {

public sealed partial class MainWindow : Window {

public NavigationView MainNavPane { get => this.MainNavView; }

public MainWindow() {
this.InitializeComponent();
AppWindow.Title = "My Audio - Cast Application";
AppWindow.TitleBar.IconShowOptions = IconShowOptions.HideIconAndSystemMenu;
AppWindow.TitleBar.BackgroundColor = Colors.Bisque;
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Bisque;

var isLeft = ApplicationData.Current.LocalSettings.Values[AppSettingKeys.IsLeftMode];
if (isLeft == null || ((bool)isLeft == true)) {
MainNavView.PaneDisplayMode = NavigationViewPaneDisplayMode.Auto;
} else {
MainNavView.PaneDisplayMode = NavigationViewPaneDisplayMode.Top;
}

String theme = ApplicationData.Current.LocalSettings.Values[AppSettingKeys.UiTheme]?.ToString();
if (theme != null) {
var t = App.GetEnum<ElementTheme>(theme);

if (this.Content is FrameworkElement rootElement) {
rootElement.RequestedTheme = t;
}
}

}

private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args) {
if (args.IsSettingsInvoked) {
sender.AlwaysShowHeader = false;
//ContentFrame.Navigate(typeof(SettingsPage));
ContentFrame.Content = new SettingsPage();
ContentFrame.Navigate(typeof(SettingsPage));
//ContentFrame.Content = new SettingsPage();
} else {
sender.AlwaysShowHeader = true;
string selectedItemTag = (String)args.InvokedItem;
sender.Header = "Sample Page " + selectedItemTag;
//ContentFrame.Navigate(typeof(ContentPage));
ContentFrame.Content = new ContentPage();
ContentFrame.Navigate(typeof(ContentPage));
//ContentFrame.Content = new ContentPage();
}
}

private void NavigationView_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args) {
ContentFrame.GoBack();
}
}
}
3 changes: 2 additions & 1 deletion MyHomeAudio/MyHomeAudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Never</AppxBundle>
<AppxBundle>Auto</AppxBundle>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>

</PropertyGroup>
Expand All @@ -26,6 +26,7 @@
<PropertyGroup>
<PublishReadyToRun>false</PublishReadyToRun>
<AssemblyVersion>1.0.0.42</AssemblyVersion>
<AppxBundlePlatforms>x86|x64</AppxBundlePlatforms>
</PropertyGroup>


Expand Down
3 changes: 1 addition & 2 deletions MyHomeAudio/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
IgnorableNamespaces="uap rescap">

<Identity
Name="b1000f29-5d74-47c6-800b-b36d7f1d18e7"
Name="Rob1000f29-5d74-47c6-800b-b36d7f1d18e7"
Publisher="CN=RKOS Software"
Version="1.0.8.0" />

Expand Down Expand Up @@ -47,6 +47,5 @@

<Capabilities>
<rescap:Capability Name="runFullTrust" />
<Capability Name="privateNetworkClientServer"/>
</Capabilities>
</Package>
53 changes: 6 additions & 47 deletions MyHomeAudio/pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
NavigationCacheMode="Enabled"
NavigationCacheMode="Required"
Loaded="Page_Loaded"

Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<!-- These styles can be referenced to create a consistent SettingsPage layout -->
Expand Down Expand Up @@ -53,7 +55,7 @@
x:Name="PageHeader"
Margin="36,24,36,0"
Style="{StaticResource TitleTextBlockStyle}"
Text="Settings" />
Text="{x:Bind SettingsTitleString, Mode=TwoWay}" />
<ScrollViewer
x:Name="contentSV"
Grid.Row="1"
Expand All @@ -63,7 +65,6 @@
VerticalScrollBarVisibility="Auto"
VerticalScrollMode="Auto">
<StackPanel Spacing="22">


<labs:SettingsCard Description="Select which app theme to display" Header="App theme">
<labs:SettingsCard.HeaderIcon>
Expand All @@ -81,48 +82,14 @@
<FontIcon Glyph="&#xF594;" />
</labs:SettingsCard.HeaderIcon>
<ComboBox x:Name="navigationLocation" SelectionChanged="navigationLocation_SelectionChanged_1">
<ComboBoxItem Content="Left" />
<ComboBoxItem Content="Left (Auto)" />
<ComboBoxItem Content="Top" />
</ComboBox>
</labs:SettingsCard>

<labs:SettingsExpander Description="Controls provide audible feedback" Header="Sound">
<labs:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xEC4F;" />
</labs:SettingsExpander.HeaderIcon>
<ToggleSwitch x:Name="soundToggle" Toggled="soundToggle_Toggled" />
<labs:SettingsExpander.Items>
<labs:SettingsCard
x:Name="SpatialAudioCard"
Header="Enable Spatial Audio"
IsEnabled="False">
<labs:SettingsCard.Description>
<HyperlinkButton Click="HyperlinkButton_Click" Content="Learn more about enabling sounds in your app" />
</labs:SettingsCard.Description>
<ToggleSwitch x:Name="spatialSoundBox" Toggled="spatialSoundBox_Toggled" />
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>

<labs:SettingsExpander x:Name="ScreenshotCard" Header="Screenshot mode">
<labs:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xEC4F;" />
</labs:SettingsExpander.HeaderIcon>
<ToggleSwitch x:Name="screenshotModeToggle" Toggled="screenshotModeToggle_Toggled" />
<labs:SettingsExpander.Items>
<labs:SettingsCard x:Name="ScreenshotFolderCard" Header="Screenshot folder">
<labs:SettingsCard.Description>
<HyperlinkButton x:Name="screenshotFolderLink" Click="screenshotFolderLink_Click" />
</labs:SettingsCard.Description>
<Button Click="Button_Click" Content="Browse" />
</labs:SettingsCard>
</labs:SettingsExpander.Items>
</labs:SettingsExpander>


<!-- About -->
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="About" />


<labs:SettingsExpander x:Name="VersionExpander" Description="© 2023 Robert'sw" Header="{StaticResource AppTitleName}" HeaderIcon="PreviewLink">
<TextBlock
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Expand All @@ -142,14 +109,6 @@
IsTextSelectionEnabled="True"
Text="{x:Bind EaVersion}" />
</labs:SettingsCard>
<!--<labs:SettingsExpander x:Name="DllVersionsExpander" Header="{x:Bind EaName}" Description="{x:Bind EaDecription}" HeaderIcon="Library">
<TextBlock
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
IsTextSelectionEnabled="True"
Text="{x:Bind EaVersion}" />
<labs:SettingsExpander.Items >
</labs:SettingsExpander.Items>
</labs:SettingsExpander> -->
</labs:SettingsExpander.Items>
</labs:SettingsExpander>
</StackPanel>
Expand Down
Loading

0 comments on commit 128c406

Please sign in to comment.