7,655
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using System.IO.IsolatedStorage;
using System.Data;
using System.Text;
using Microsoft.Phone.Shell;
using System.IO;
using System.IO.IsolatedStorage;
namespace text
{
public partial class MainPage : PhoneApplicationPage
{
public string filename;
public string[] filename_list;
public class note
{
public string titile_tbx1 { get; set; }
public string body_txb1 { get; set; }
}
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
List<note> notes = new List<note>();
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
{
filename_list = iso.GetFileNames(); //获得根目录的所有文件名称列表
int i = filename_list.Length; //获取文件名列表长度
for (int a = 0; a < i; a++) //通过for循环 依次写入note 由a决定
{
using (IsolatedStorageFile file=IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream=file.OpenFile (filename_list[a],FileMode.OpenOrCreate ,FileAccess.ReadWrite ))
{
using (StreamReader reader = new StreamReader(stream))
{
notes.Add(new note { titile_tbx1 = filename_list[a], body_txb1 = reader.ReadToEnd() });
}
}
}
}
}
_LB_main.ItemsSource = notes; //
}
private void _hybtn_1_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton myhybtn = e.OriginalSource as HyperlinkButton;
filename = myhybtn.Content.ToString();
this.NavigationService.Navigate(new Uri ("edit.xaml?file="+filename,UriKind.Relative ));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;
using System.IO;
using System.Text;
namespace text
{
public partial class edit : PhoneApplicationPage
{
public string data;
public edit()
{
InitializeComponent();
}
private void _tbx_body_TextChanged(object sender, TextChangedEventArgs e)
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = file.OpenFile(_tbx_title.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(_tbx_body.Text);
writer.Close();
}
}
}
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = file.OpenFile(_tbx_title.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(stream);
writer.WriteLine(_tbx_body.Text);
writer.Close();
}
}
this.NavigationService.Navigate(new Uri("/Mainpage.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e); //设置一个data string 如果出现异常,就跳出代码块,直接进入catch return
try
{
data = NavigationContext.QueryString["file"];
}
catch (System.Exception ex)
{
return;
}
if (!string.IsNullOrEmpty(data))
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = file.OpenFile(data,FileMode.OpenOrCreate,FileAccess.Read))
{
using (StreamReader reader = new StreamReader(stream))
{
_tbx_title.Text = data;
_tbx_body.Text = reader.ReadToEnd();
}
}
}
}
}
private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
file.DeleteFile(_tbx_title.Text);
this.NavigationService.Navigate(new Uri("/Mainpage.xaml", UriKind.Relative));
}
}
}
}