从xap文件中读取文件

读取图片文件:

SteamResourceInfo sri=Application.GetResourceStream(new Uri("filename;component/assets/"+dm.spic,UriKind.Relative));
BitmapImage bi
=new BitmapImage();
bi.SetSource(sri.Stream);
Image img
=new Image();
img.Source
=bi;

读取XML文件并用Linq来初始化数据:

public void InitDataMode() {
StreamResouceInfo sri
=Application.GetResourceStream(new Uri("filename;component/Data/DataModel.xml",UriKind.Relative));
XmlReader reader
=XmlReader.Create(sri.Stream);
XDocument document
=XDocument.Load(reader);
listData
=(from c in document.Descendants("model")
    select 
new DataModel
    {
      t1
=c.Element("t1").Value,
      t2
=c.Element("t2").Value,
      t3
=c.Element("t3").Value,
      url
=c.Element("url").Value,
      spic
=c.Element("spic").Value,
      bpic
=c.Element("bpic").Value
    }).ToList
<DataModel>();
sri.Stream.Close();
sri.Stream.Dispose();
}

注解:

StreamResourceInfo sri = Application.GetResourceStream(new Uri("{0};component/{1}", UriKind.Relative));

0为xap程序集的名字,

1为要读取的文件在在xap中的路径。

原文地址:https://www.cnblogs.com/lovecode/p/1403393.html