页面之间通过IsolatedStorageFile传值、ListBox绑定数据、查看手机内容已经程序所用地控件大小
代码很简单,直接上代码,不懂的地方可以PM我
ListBox绑定页后台代码
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.IsolatedStorage;
using System.IO;namespace PhoneApp2
{
public partial class ListBox : PhoneApplicationPage
{
public ListBox()
{
InitializeComponent();
Loaded += new RoutedEventHandler(ListBox_Loaded);
}void ListBox_Loaded(object sender, RoutedEventArgs e)
{
bindList();
}private void bindList()
{
IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication();string[] fileName = appStorage.GetFileNames();
DemoListBox.ItemsSource = fileName;
}private void fileNameHyperlinkButton_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton link = (HyperlinkButton)sender;string uri = String.Format("/PhoneApp2;component/Page2.xaml?id={0}", link.Content);
NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}private void saveButton_Click(object sender, RoutedEventArgs e)
{
bandingData("ruanman.bat", "WP7开发者:http://dev.ruanman.net");
bandingData("ruanman.txt", "WP8资讯:http://www.ruanman.net");
bandingData("ruanman.xml", "软曼论坛:http://bbs.ruanman.net");bindList();
}private void bandingData(string fileName, string fileContent)
{
IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication();if (!appStorage.FileExists(fileName))
{
using (var file = appStorage.CreateFile(fileName))
{
StreamWriter writer = new StreamWriter(file);writer.Write(fileContent);
}
}
}private void button1_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication();appStorage.Remove();
bindList();
}
}
}
第二个页面,接受传参页面后台代码
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.IsolatedStorage;
using System.IO;namespace PhoneApp2
{
public partial class Page2 : PhoneApplicationPage
{
public Page2()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Page2_Loaded);
}void Page2_Loaded(object sender, RoutedEventArgs e)
{
var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
string fileName = NavigationContext.QueryString["id"];using (var file = appStorage.OpenFile(fileName, System.IO.FileMode.Open))
{
using (StreamReader reader = new StreamReader(file))
{
contentTextBlock.Text = reader.ReadToEnd();
}
}}
}
}
重点获取空间大小
appStorage.Quota.ToString();//独立存储最大空间
appStorage.AvailableFreeSpace.ToString(); //可用空间大小