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>
![](http://hi.csdn.net/attachment/201111/29/0_1322582820Hg3L.gif)
而后在后台代码里边写绑定的方法和数据源如:
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;
![](http://hi.csdn.net/attachment/201111/29/0_1322582887wuH0.gif)
即可实现数据的动态绑定显示。
显示如:
![](http://hi.csdn.net/attachment/201111/29/0_13225829156G42.gif)
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;
}