簡體   English   中英

如何:從 PackURI 加載嵌入式動態資源數據

[英]How To : Load Embedded Dynamic Resource Data from PackURI

如何只加載資源的任何數據,然后確定數據的類型並將其加載到元素控件上?

public static dynamic ReadResource(System.String Parameter1)
{
    return new System.Uri(@"pack://application:,,,/RESOURCES/" + Parameter1, System.UriKind.RelativeOrAbsolute);
}

var testing = ReadResource("resource1");

if (testing.GetType() == typeof(System.String)
    MyLabel.Content = testing;

謝謝;

解決方案

📘 WPF 應用程序資源、內容和數據文件
研究了解決方案並重構了代碼示例;

public static dynamic ReadResource(System.String Parameter1){
var _myPackURI_ = new System.Uri("/RESOURCES/"+Parameter1, System.UriKind.RelativeOrAbsolute); //[?] Pack URI;
var _myStream_  = System.Windows.Application.GetResourceStream( _myPackURI_ );                 //[?] Resource Stream;
var _myReader_  = new System.IO.StreamReader( _myStream_.Stream );                             //[?] Stream Reader;
return _myReader_.ReadToEnd(); //[?] Stream Reader Operation;
}


/* ... */
var testing = ReadResource("resource1");
if (testing.GetType() == typeof(System.String))
System.Console.WriteLine( testing );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM