Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Page
- x:Class="App3.MainPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:App3"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d">
- <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <ToggleSwitch OffContent="Light"
- OnContent="Dark"
- x:Name="toggleSwitch"
- Header="ToggleSwitch"
- Toggled="toggleSwitch_Toggled"/>
- </Grid>
- </Page>
- using System;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.Storage;
- namespace App3
- {
- public sealed partial class MainPage : Page
- { ApplicationDataContainer localSettings = null;
- ApplicationDataContainer local = null;
- const string toggleSwitch_Toggle = "example";
- public MainPage()
- { ApplyUserSettings();
- this.InitializeComponent();
- localSettings = ApplicationData.Current.LocalSettings;
- local = ApplicationData.Current.LocalSettings; }
- private async void toggleSwitch_Toggled(object sender, RoutedEventArgs e)
- { StorageFolder local = ApplicationData.Current.LocalFolder;
- var dataFolder = await local.CreateFolderAsync("Data Folder", CreationCollisionOption.OpenIfExists);
- var file = await dataFolder.CreateFileAsync("SwitchBWThemeMode.txt", CreationCollisionOption.ReplaceExisting);
- if (toggleSwitch.IsOn)
- { await FileIO.WriteTextAsync(file, "on"); }
- else await FileIO.WriteTextAsync(file, "off"); }
- private async void ApplyUserSettings()
- { try
- { StorageFolder local = ApplicationData.Current.LocalFolder;
- var dataFolder = await local.GetFolderAsync("Data Folder");
- var file = await dataFolder.GetFileAsync("SwitchBWThemeMode.txt");
- String SwitchBWThemeMode = await FileIO.ReadTextAsync(file);
- if (SwitchBWThemeMode == "on")
- { RequestedTheme = ElementTheme.Dark;
- toggleSwitch.IsOn = true; }
- else RequestedTheme = ElementTheme.Light;
- toggleSwitch.IsOn = false;
- }
- catch (Exception) { }
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement