在Silverlight中还有一种叫做IsolatedStorage的存储机制,他存储信息的方式类似于我们的cookie, IsolatedStorage存储独立于每一个Silverlight的application,换句话说我们加载多个Silverlight应用程序是他们不会相互影响,我们这样就可以在silverlight 下次运行的时从IsolatedStorage中提取一些有用的数据,这对我们来说是很好的一件事吧~

使用islatedstorage也十分简单,不废话了 还是上个实例看吧.

XAML:

使用 IsolatedStorageFileStream 存储信息<UserControl x:Class="SilverlightApplication10.Page"
使用 IsolatedStorageFileStream 存储信息    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
使用 IsolatedStorageFileStream 存储信息    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" 
使用 IsolatedStorageFileStream 存储信息    Width
="400" Height="300">
使用 IsolatedStorageFileStream 存储信息    
<Canvas x:Name="myCanvas" Background="White">
使用 IsolatedStorageFileStream 存储信息        
<TextBlock MouseLeftButtonDown="myTxt_MouseLeftButtonDown" Height="31" Width="119" Canvas.Left="142" Canvas.Top="139" Text="click me" TextWrapping="Wrap" x:Name="myTxt"/>
使用 IsolatedStorageFileStream 存储信息    
</Canvas>
使用 IsolatedStorageFileStream 存储信息
</UserControl>

我们用IsolatedStorageFile.GetUserStoreForApplication()获取一个IsolatedStorage文件对象.

随后我们将创获取IsolatedStorageFileStream对象,再将文件已流的形式写入.

注:(using System.IO.IsolatedStorage;using System.IO;)

 

使用 IsolatedStorageFileStream 存储信息private void SaveData(string _data, string _fileName)
        }

 

这样我们就完成写入工作,读取也同样简单~

 

使用 IsolatedStorageFileStream 存储信息private string LoadData(string _fileName)
        }

 

就此我们就完成了文件的读写,在此说明一点Silverlight默认分配一个application的IsolatedStorage空间是1MB.

当然我们也可以更改这个限额~ 这个问题我下次再给大家说吧~

Source codeIsolatedStorageDEMO1

相关文章:

  • 2021-06-20
  • 2021-12-06
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-27
  • 2021-09-12
相关资源
相似解决方案