Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Navigation;
  8. using Microsoft.Phone.Controls;
  9. using System.IO.IsolatedStorage;
  10. using Microsoft.Phone.Shell;
  11.  
  12. namespace Laboratory2
  13. {
  14.     public partial class Page1 : PhoneApplicationPage
  15.     {
  16.         public Page1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void Box2_TextChanged(object sender, TextChangedEventArgs e)
  22.         {
  23.  
  24.         }
  25.  
  26.         protected override void OnNavigatedTo(NavigationEventArgs e)
  27.         {
  28.             base.OnNavigatedTo(e);
  29.             String sample = NavigationContext.QueryString["toPass"];
  30.             Box2.Text = sample;
  31.         }
  32.  
  33.         private void Button_Click_1(object sender, RoutedEventArgs e)
  34.         {
  35.             IsolatedStorageSettings set = IsolatedStorageSettings.ApplicationSettings;
  36.             this.NavigationService.Navigate(new Uri("/MainPage.xaml?", UriKind.Relative));
  37.         }
  38.     }
  39. }
  40.  
  41.  
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Linq;
  45. using System.Net;
  46. using System.Windows;
  47. using System.IO;
  48. using System.IO.IsolatedStorage;
  49. using System.Windows.Controls;
  50. using System.Windows.Navigation;
  51. using Microsoft.Phone.Controls;
  52. using Microsoft.Phone.Shell;
  53. using Laboratory2.Resources;
  54.  
  55. namespace Laboratory2
  56. {
  57.     public partial class MainPage : PhoneApplicationPage
  58.     {
  59.         // Constructor
  60.         public MainPage()
  61.         {
  62.             InitializeComponent();
  63.  
  64.             // Sample code to localize the ApplicationBar
  65.             //BuildLocalizedApplicationBar();
  66.         }
  67.  
  68.         private void saveText(string filename, string text)
  69.         {
  70.             using (IsolatedStorageFile isf =
  71.                     IsolatedStorageFile.GetUserStoreForApplication())
  72.             {
  73.                 using (IsolatedStorageFileStream rawStream =
  74.                                     isf.CreateFile(filename))
  75.                 {
  76.                     StreamWriter writer = new StreamWriter(rawStream);
  77.                     writer.Write(text);
  78.                     writer.Close();
  79.                 }
  80.             }
  81.         }
  82.  
  83.         private bool loadText(string filename, out string result)
  84.         {
  85.             using (IsolatedStorageFile isf =
  86.                     IsolatedStorageFile.GetUserStoreForApplication())
  87.             try
  88.             {
  89.                 using (IsolatedStorageFileStream rawStream =
  90.                         isf.OpenFile(filename, System.IO.FileMode.Open))
  91.                 {
  92.                     StreamReader reader = new StreamReader(rawStream);
  93.                     result = reader.ReadToEnd();
  94.                     reader.Close();
  95.                     return true;
  96.                 }
  97.             }
  98.             catch
  99.             {
  100.                 result = "";
  101.                 return false;
  102.             }
  103.         }
  104.  
  105.         String toPass = "";
  106.         private void Button_Click_1(object sender, RoutedEventArgs e)
  107.         {
  108.             this.NavigationService.Navigate(new Uri("/Page1.xaml?toPass=" + Box1.Text,UriKind.Relative));
  109.         }
  110.  
  111.         private void Save_Click(object sender, RoutedEventArgs e)
  112.         {
  113.             saveText("test.txt", Box1.Text);
  114.         }
  115.  
  116.         private void Load_Click(object sender, RoutedEventArgs e)
  117.         {
  118.             string text;
  119.  
  120.             if (loadText("test.txt", out text))
  121.             {
  122.                 Box1.Text = text;
  123.             }
  124.             else
  125.             {
  126.                 Box1.Text = "Type anything here";
  127.             }
  128.         }
  129.  
  130.         private void Button_Click_2(object sender, RoutedEventArgs e)
  131.         {
  132.             string text;
  133.  
  134.             if (loadText("test.txt", out text))
  135.             {
  136.                 Box1.Text = text;
  137.             }
  138.             else
  139.             {
  140.                 Box1.Text = "Type anything here";
  141.             }
  142.         }
  143.  
  144.         private void Box1_TextChanged(object sender, TextChangedEventArgs e)
  145.         {
  146.  
  147.         }
  148.  
  149.  
  150.  
  151.        
  152.  
  153.        
  154.  
  155.         // Sample code for building a localized ApplicationBar
  156.         //private void BuildLocalizedApplicationBar()
  157.         //{
  158.         //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
  159.         //    ApplicationBar = new ApplicationBar();
  160.  
  161.         //    // Create a new button and set the text value to the localized string from AppResources.
  162.         //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
  163.         //    appBarButton.Text = AppResources.AppBarButtonText;
  164.         //    ApplicationBar.Buttons.Add(appBarButton);
  165.  
  166.         //    // Create a new menu item with the localized string from AppResources.
  167.         //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
  168.         //    ApplicationBar.MenuItems.Add(appBarMenuItem);
  169.         //}
  170.     }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement