Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <Page
  2. x:Class="App3.MainPage"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:App3"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  11. <ToggleSwitch OffContent="Light"
  12. OnContent="Dark"
  13. x:Name="toggleSwitch"
  14. Header="ToggleSwitch"
  15. Toggled="toggleSwitch_Toggled"/>
  16. </Grid>
  17. </Page>
  18.  
  19. using System;
  20. using Windows.UI.Xaml;
  21. using Windows.UI.Xaml.Controls;
  22. using Windows.Storage;
  23.  
  24. namespace App3
  25. {
  26. public sealed partial class MainPage : Page
  27. { ApplicationDataContainer localSettings = null;
  28. ApplicationDataContainer local = null;
  29. const string toggleSwitch_Toggle = "example";
  30.  
  31. public MainPage()
  32. { ApplyUserSettings();
  33. this.InitializeComponent();
  34. localSettings = ApplicationData.Current.LocalSettings;
  35. local = ApplicationData.Current.LocalSettings; }
  36.  
  37. private async void toggleSwitch_Toggled(object sender, RoutedEventArgs e)
  38. { StorageFolder local = ApplicationData.Current.LocalFolder;
  39. var dataFolder = await local.CreateFolderAsync("Data Folder", CreationCollisionOption.OpenIfExists);
  40. var file = await dataFolder.CreateFileAsync("SwitchBWThemeMode.txt", CreationCollisionOption.ReplaceExisting);
  41. if (toggleSwitch.IsOn)
  42. { await FileIO.WriteTextAsync(file, "on"); }
  43. else await FileIO.WriteTextAsync(file, "off"); }
  44.  
  45. private async void ApplyUserSettings()
  46. { try
  47. { StorageFolder local = ApplicationData.Current.LocalFolder;
  48. var dataFolder = await local.GetFolderAsync("Data Folder");
  49. var file = await dataFolder.GetFileAsync("SwitchBWThemeMode.txt");
  50. String SwitchBWThemeMode = await FileIO.ReadTextAsync(file);
  51.  
  52. if (SwitchBWThemeMode == "on")
  53. { RequestedTheme = ElementTheme.Dark;
  54. toggleSwitch.IsOn = true; }
  55. else RequestedTheme = ElementTheme.Light;
  56. toggleSwitch.IsOn = false;
  57. }
  58. catch (Exception) { }
  59. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement