<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      WPF整理-二進制資源和內容

      WPF中的Binary Resource(二進制資源)是相對于前面所說的Logical resource(邏輯資源)而說的,一般指Image、XML文件等。

      注意:這里說的是Resource"資源",和Content"內容"是不同的。

      1.Content VS Resource

      一般我們向工程中添加一個二進制的資源,如圖片。我們設置它的屬性,設置成資源和內容是不同的!

      簡單的說下兩者的區別:

      When the Build Action is set to Content (as in the jellyfish example), the resource is not
      included in the assembly. This makes it more appropriate when the resource needs to change
      often (perhaps by a designer) and a rebuild would be undesirable. Also, if the resource is
      large, and not always needed, it's better to leave it off to the resulting assembly. Note that to
      access the resource, the exact same syntax is used. This is possible because WPF adds the
      AssemblyAssociatedContentFile attribute to the assembly, specifying the name of the
      resource file. Here's a view with .NET Reflector:”

      “That's why we were able to replace the jellyfish image with a desert image and get it to show
      correctly given the name jellyfish.jpg without doing any kind of rebuilding.” 

      WHILE

      When the Build Action is set to Resource, the image file is stored as a resource inside the compiled
      assembly. This is because the Build Action was set to Resource on the image. This makes
      the actual image file unnecessary when deploying the application.
      These resources are part of the assembly and are stored in a resource named
      MyApplication.g.resources, where MyApplication is the name of the
      assembly. Here's a snapshot from .NET Reflector:”

      2.Access

      對于Image,無論設置成Content,還是Resource,都可以很方便的訪問,如下:

      xaml中

      <Image Source="Images/5.png" Width="100" Height="100" />
      <Image Source="Images/6.png" Width="100" Height="100" />

      C#中

      image1.Source = new BitmapImage(new Uri("Images/5.png", UriKind.Relative));
      image2.Source = new BitmapImage(new Uri("Images/6.png", UriKind.Relative));

      并沒有區別。

       3.Point of Interest

      其他的,如xml file,兩者訪問方法就有區別了!

      “Accessing a binary resource in XAML is pretty straightforward, but this works for standard
      resources such as images. Other types of resources may be used in code, and this requires
      a different approach.”

      譬如有這樣的一個xml file

      如果,我們將生產操作設置成為Content,則我們可以這樣訪問:

                  var books = XElement.Load("Xml/books.xml");
             var bookList = from book in books.Elements("Book")
                                 orderby (string)book.Attribute("Author")
                                 select new
                                 {
                                     Name=(string)book.Attribute("Name"),
                                     Author=(string)book.Attribute("Author")
                                 };
                  foreach (var book in bookList)
                  {
                      txtBook.Text += book.ToString() + Environment.NewLine;
                  }

      或者是:

                  var info = Application.GetContentStream(new Uri("Xml/books.xml", UriKind.Relative));
                  var books = XElement.Load(info.Stream);            
             var bookList = from book in books.Elements("Book")
                                 orderby (string)book.Attribute("Author")
                                 select new
                                 {
                                     Name=(string)book.Attribute("Name"),
                                     Author=(string)book.Attribute("Author")
                                 };
                  foreach (var book in bookList)
                  {
                      txtBook.Text += book.ToString() + Environment.NewLine;
                  }

      如果設置成Resource,則以上程序會報告無法找到xml file。


      因此,設置成Resource時,我們應該這樣訪問:

                  var info = Application.GetResourceStream(new Uri("Xml/books.xml", UriKind.Relative));
                  var books = XElement.Load(info.Stream);
      var bookList = from book in books.Elements("Book")
                                 orderby (string)book.Attribute("Author")
                                 select new
                                 {
                                     Name=(string)book.Attribute("Name"),
                                     Author=(string)book.Attribute("Author")
                                 };
                  foreach (var book in bookList)
                  {
                      txtBook.Text += book.ToString() + Environment.NewLine;
                  }

      兩種情況下,程序運行如下:

        

      posted @ 2013-07-02 07:30  DebugLZQ  閱讀(2039)  評論(2)    收藏  舉報
      主站蜘蛛池模板: 亚洲精品麻豆一二三区| 午夜福利高清在线观看| 日日躁夜夜躁狠狠躁超碰97 | 国产成人亚洲综合图区| 1024你懂的国产精品| 四虎永久免费高清视频| 青青国产揄拍视频| 菠萝菠萝蜜午夜视频在线播放观看| 欧美视频二区欧美影视| 色视频在线观看免费视频| 久久自己只精产国品| av午夜久久蜜桃传媒软件| 国产一区二区三区无遮挡| 国产色无码专区在线观看| 在线日韩日本国产亚洲| 精品国产AV无码一区二区三区 | 给我中国免费播放片在线| 国产精品视频亚洲二区| 国产美女久久久亚洲综合 | 99在线小视频| 狠狠色丁香婷婷综合尤物| 国产精品不卡一二三区 | 精品国产乱码久久久久APP下载| 无码精品国产VA在线观看DVD| 亚洲色一区二区三区四区| 強壮公弄得我次次高潮A片| 久久久午夜精品福利内容| 疯狂做受xxxx高潮欧美日本| 欧美精品V欧洲精品| 久久国产精品老女人| 亚洲区一区二区三区视频| 少妇人妻偷人精品视频| 国产成人高清在线重口视频| 欧美乱妇高清无乱码免费| 日本熟妇浓毛hdsex| 亚洲国产精品成人无码区| 免费AV片在线观看网址| 国产精品午夜福利免费看| 欧洲尺码日本尺码专线美国又| 亚洲精品久久久久国色天香| 精品人妻av中文字幕乱|