四天玩转wp7第三天作业
主要代码:解析就等到理解更进一步了再说吧。先记录下了
using System;
using System.Windows;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;
namespace Day3Homeword
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void appBar_Edit(object sender, EventArgs e)
{
if (noteTextBlock.Visibility == System.Windows.Visibility.Visible)
{
noteTextBox.Text = noteTextBlock.Text;
noteTextBlock.Visibility = System.Windows.Visibility.Collapsed;
noteTextBox.Visibility = System.Windows.Visibility.Visible;
noteTextBox.Focus();
}
}
private void appBar_Save(object sender, EventArgs e)
{
if (noteTextBox.Visibility == System.Windows.Visibility.Visible)
{
saveNote();
noteTextBlock.Text = noteTextBox.Text;
noteTextBlock.Visibility = System.Windows.Visibility.Visible;
noteTextBox.Visibility = System.Windows.Visibility.Collapsed;
}
}
private void appBar_Delete(object sender, EventArgs e)
{
noteTextBox.Text = "";
saveNote();
noteTextBlock.Text = "";
noteTextBlock.Visibility = System.Windows.Visibility.Visible;
noteTextBox.Visibility = System.Windows.Visibility.Collapsed;
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
loadNote();
}
private void loadNote()
{
var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (var fileStream = appStorage.OpenFile("note.txt", System.IO.FileMode.OpenOrCreate))
{
using (StreamReader sr = new StreamReader(fileStream))
{
noteTextBlock.Text = sr.ReadToEnd();
}
}
}
private void saveNote()
{
var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (var fileStream=appStorage .OpenFile ("note.txt",FileMode.Create ))
{
using (StreamWriter sw=new StreamWriter (fileStream ))
{
sw.WriteLine(noteTextBox .Text );
}
}
}
}
}