Metro学习笔记+心得+体会(二)

写在前边的话:

  这些日子就一星期更新一篇博客吧,有不足之处还请各位高人多多指点。。。。。

by 15 岁的爱好编程者

 

正文:

展示一下实现的效果和用到的技术:如下图:

 

主要功能很简单,就是获取当前账户内的有关信息和修改用户的头像。虽是简单,但对于我这个新手来说,也是蛮有难度的。程序中使用了有关Frame,FileOpenPicker等的有关知识,关于具体讲解,请往↓看。

 

首先讲一下frame、

frame其实就是一框架,frame用法很简单,我在此程序中只用了它的一个属性(Content)一个方法(Navigate),先展示下源码:

Grid grid=new Grid();
Frame frame1=new Frame();
frame1.Content=grid;//设置Frame的内容
Frame frame2=new Frame();
frame2.Natigate(typeof(MainPage),this);//设置其显示的界面,这里指定显示MainPage的内容

Frame的Natigate方法有两个参数,第一个参数为一个type对象,指定要加载的那个窗体,其格式是“命名空间+.+窗体类名”假设要在window窗体下点一个按钮使Frame加载命名空间下的Windows窗体,代码是这样写:

Frame frame=new Frame();
frame.Natigate(Type.GetType(typeof(window).namespace)+window1),this);

 

第二个参数是指示父窗体,在这里就不用多说了。

 

接着讲下FileOpenPicker、

FileOpenPicker是打开计算机中一些库的一个类,可以用它很方便的打开图片库,下载库,音乐库什么的。咱还是用代码说话:

FileOpenPicker videoPicker = new FileOpenPicker
{
     ViewMode = PickerViewMode.Thumbnail,
     SuggestedStartLocation = PickerLocationId.VideosLibrary,
     FileTypeFilter = { ".mp4", ".mpeg", ".mpeg", ".wmv", ".mov" }
};

ViewMode指示FileOpenPicker的显示模式,为Thumbnail还是为List;SuggestedStartLocation指示FileOpenPicker打开那个库;FileTypeFilter指示扩展名。

接下来将它显示到一个Image中:

            FileOpenPicker imagePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                FileTypeFilter = {".jpg",".jpge",".bmp",".png"}

            };
            StorageFile image =await imagePicker.PickSingleFileAsync();
            if (image != null)
            {
                Windows.System.UserProfile.SetAccountPictureResult result=await Windows.System.UserProfile.UserInformation.SetAccountPicturesAsync(null,image,null);
                if (result == Windows.System.UserProfile.SetAccountPictureResult.Success)
                {
                    rootpage.showContent("设置成功!");
                }
                else 
                {
                    rootpage.showContent("设置失败!");
                }


要注意的是,需要在该段代码所属处理事件的前部加关键字async。还要引用using Windows.Storage和
using Windows.Storage.Pickers这两个命名空间

最后要阐述的是,所有有关计算机账户操作的方法都在Windows.System.UserProfile命名空间中,具体的可以按“.”查看。

 

**另附源码下载地址************************

https://skydrive.live.com/redir?resid=F408A3D3DF420664!180&authkey=!ADzK4h9Z7IiN-EE

***************************************

源码由于时间问题质量不太好,大家海涵哈。。。。。。。

 

posted @ 2012-05-26 15:31  deepwzh  阅读(1067)  评论(0编辑  收藏  举报