简体   繁体   English

从代码访问ResourceDictionary(不隐藏代码)

[英]Access ResourceDictionary from Code(not Code-Behind)

in my application, i have a resource dictionary defined as a separate file. 在我的应用程序中,我将资源字典定义为单独的文件。 Now i want to access this dictionary from ac#-file ( no code-behind file! ) 现在我想从ac#文件访问此词典( 无代码隐藏文件!

What would be the best(fastest, cleanest) way to do this? 最好的方法(最快,最干净)是什么?

  • Create a ResourceDictionary in code and merge it with the existing one? 用代码创建ResourceDictionary并将其与现有代码合并?

  • Add the ResourceDictionary to the application's resources and access them with Application.Current.Resources? 将ResourceDictionary添加到应用程序的资源中,然后使用Application.Current.Resources?访问它们。

  • Some other way?? 其他方式?

Greets, 映入眼帘,

Jürgen 于尔根

You can load resource dictionaries using App.LoadComponent(), eg: 您可以使用App.LoadComponent()加载资源字典,例如:

var d = (ResourceDictionary)App.LoadComponent(new Uri("Dictionary1.xaml",UriKind.Relative));

Not really sure if it would be the fastest, but it is probably one of the cleaner ways. 不确定是否会最快,但这可能是更干净的方法之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM