根据 Windows 应用商店应用的部分软件作为参考
使用Vs2012 制作了一个 简单的 Windows8 图库,图片展示软件
程序界面如下
(1)主界面:
(2)点击单个图片进入内容页
首页图片加载代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.New)
{
for (int i = 0; i < 9; i++)
{
Image im1 = new Image();
im1.Source = new BitmapImage(new Uri("ms-appx:///Images/" + (i + 1) + ".jpg"));
im1.Width = 400;
im1.Height = 400;
Thickness tk = new Thickness();
tk.Top = 10;
tk.Left = 20;
tk.Right = 40;
tk.Bottom = 10;
im1.Margin = tk;
im1.Tapped += new TappedEventHandler(im1_Click);
spPicture.Children.Add(im1);
}
}
}
private void im1_Click(object sender, RoutedEventArgs e)
{
Image img1 = (Image)sender;
string[] imgNames = ((BitmapImage)img1.Source).UriSource.ToString().Split('/');
string imgName = imgNames[2].Substring(0, 1);
Frame.Navigate(typeof(Info), imgName);
}
内容页,读取文档代码:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
txtTitle.Text = "图 片 " + e.Parameter.ToString();
img.Source = new BitmapImage(new Uri("ms-appx:///Images/" + e.Parameter.ToString() + ".jpg"));
//"ms-appx:///Images/txt/" + e.Parameter.ToString() + ".txt"
string path = "ms-appx:///Images/txt/" + e.Parameter.ToString() + ".txt";
Uri baseUri = new Uri(path);
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(baseUri);
if (file != null)
{
//按行读取文件内容
//IList x = await FileIO.ReadLinesAsync(file);
//读取文件中所有内容
string txtIn = await FileIO.ReadTextAsync(file,Windows.Storage.Streams.UnicodeEncoding.Utf8);
txtInfo.Content = txtIn;
}
}
程序源代码下载地址:
http://download.csdn.net/detail/xin70v3/5046231