WP7学习笔记002

1、Panorama控件的多值动态数据绑定

现在xaml页面创建Panorama控件然后创建绑定数据的模板:

            <controls:Panorama Name="par1" Title="用户信息">
            <controls:Panorama.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=UserName}"></TextBlock>
                </DataTemplate>
            </controls:Panorama.HeaderTemplate>
            <controls:Panorama.ItemTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Path=Conetent}"/>
                </DataTemplate>
            </controls:Panorama.ItemTemplate>
        </controls:Panorama>

 

而后在后台代码里边写绑定的方法和数据源如:

            ObservableCollection<UserInfocs> userinfolib = new ObservableCollection<UserInfocs>();
            UserInfocs user1 = new UserInfocs() { ID = 1, UserName = "zhang", Conetent = "wodexinxi xixnxi" };
            UserInfocs user2 = new UserInfocs() { ID = 2, UserName = "li", Conetent = "wodexinxi123456" };
            UserInfocs user3 = new UserInfocs() { ID = 3, UserName = "zhang", Conetent = "wodexinxi 789456123" };
            userinfolib.Add(user1);
            userinfolib.Add(user2);
            userinfolib.Add(user3);
            par1.ItemsSource = userinfolib;

 

即可实现数据的动态绑定显示。

显示如:

 

 

 

 

 

2、独立存储保存和读取图片的方法

 public static void SaveToLocalStorage(string imageFileName)
        {

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists(imageFileName))
                {
                    store.DeleteFile(imageFileName);
                }
                //用Substring获取文件名
                string imgName = imageFileName.Substring(imageFileName.LastIndexOf('\\') + 1);
                IsolatedStorageFileStream fileStream = store.CreateFile(imgName);

                StreamResourceInfo sri = null;
                Uri uri = new Uri(imageFileName, UriKind.Relative);

                sri = Application.GetResourceStream(uri);

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmap);
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);

                fileStream.Close();
               
            }
        }
        /// <summary>
        /// 已知在存储空间中的路径+名,读出来返回一张图片
        /// </summary>
        /// <param name="imageFileName">存储空间中的路径+名</param>
        /// <returns>BitMapImage格式的一张图片,可以直接给Image控件设置数据源</returns>
        public static BitmapImage  LoadImageFromLocalStorge(string imageFileName)
        {
            var store = IsolatedStorageFile.GetUserStoreForApplication();
       
            BitmapImage bmp = new BitmapImage();
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(imageFileName, FileMode.Open, FileAccess.Read))
                {
                    bmp.SetSource(fileStream);
                }
            }
            return bmp;
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值