如何从独立存储中获取图像
有这个 XAML
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" Name="list">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Image Height="100" Width="100" Source="{Binding Img}" Margin="12,0,9,0"/>
<StackPanel Width="311">
<TextBlock Text="{Binding Pos}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我在代码中
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream isoStoreStream = isoStore.OpenFile("chart.xml", FileMode.Open);
using (StreamReader reader = new StreamReader(isoStoreStream))
{
XElement xml = XElement.Parse(reader.ReadToEnd());
var list = from var in xml.Descendants("Pos")
select new Single
{
Pos = Int32.Parse(var.Attribute("id").Value),
Img = how read from isolated storage the image id.jpg?
};
public class Single
{
public int Pos { set; get; }
public ??? Img { set; get; }
}
:我已经将图像保存到独立存储中,但问题是:如何从独立存储中读取名称为 id.jpg(1.jpg, 2.jpg, 3.jpg ...)?
I have this XAML
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" Name="list">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<!--Replace rectangle with image-->
<Image Height="100" Width="100" Source="{Binding Img}" Margin="12,0,9,0"/>
<StackPanel Width="311">
<TextBlock Text="{Binding Pos}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
In the Code:
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream isoStoreStream = isoStore.OpenFile("chart.xml", FileMode.Open);
using (StreamReader reader = new StreamReader(isoStoreStream))
{
XElement xml = XElement.Parse(reader.ReadToEnd());
var list = from var in xml.Descendants("Pos")
select new Single
{
Pos = Int32.Parse(var.Attribute("id").Value),
Img = how read from isolated storage the image id.jpg?
};
public class Single
{
public int Pos { set; get; }
public ??? Img { set; get; }
}
I have already saved the images into isolated storage but the problem is: how can I read from isolated storage the image that have names like id.jpg(1.jpg, 2.jpg, 3.jpg...)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的
Single
类中,Img
属性应为 ImageSource 类型。要设置此属性(从isolatedStorage读取图像),您可以执行以下操作:然后在代码片段中:
In your
Single
Class theImg
property should be of type ImageSource. To set this property (read the image from IsolatedStorage) you can do this:Then in your code snippet:
这是一个关于如何写入和读取 ISO 存储的非常完整的示例。
http://www.codeproject。 com/Articles/38636/Saving-Bitmaps-to-Isolated-Storage-in-Silverlight-.aspx
Here is a very complete example of how to write to and read from ISO storage.
http://www.codeproject.com/Articles/38636/Saving-Bitmaps-to-Isolated-Storage-in-Silverlight-.aspx