zoukankan      html  css  js  c++  java
  • 从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中的路径。

  • 相关阅读:
    为什么C++(感谢waterwalk翻译)
    容器操作笔记
    如此理解面向对象编程
    C++初学者小细节(不定时更新)
    Sales_item 专题
    10步让你成为更优秀的程序员
    C++ PRIMER 笔记
    C++ 异常处理
    透明度 rgba 和 opacity 的区别
    盒模型
  • 原文地址:https://www.cnblogs.com/lovecode/p/1403393.html
Copyright © 2011-2022 走看看