如何:从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;

谢谢;

SOLUTION

📘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 );

相关内容

  • 没有找到相关文章

最新更新