简体   繁体   English

从UWP类库中的代码获取XAML资源

[英]Get a XAML resource from code in a UWP Class Library

Hi everyone and Merry Chrismas. 大家好,圣诞快乐。

I already know how to get a XAML resource in a main UWP project, but is it possible to get a ResourceDictionary's XAML resource from a class, both contained in a UWP Class Library? 我已经知道如何在主UWP项目中获取XAML资源,但是是否可以从都包含在UWP类库中的类中获取ResourceDictionary的XAML资源呢?

Thanks for your attention. 感谢您的关注。

Just call this line in your C# code: 只需在您的C#代码中调用此行即可:

Application.Current.Resources["Key"]

And you'll get the resource named "Key". 然后,您将获得名为“ Key”的资源。

If you cannot compile this method in your class library, it may be that your class library is not designed especially for UWP, so you can't try to get a resource there. 如果您不能在类库中编译此方法,则可能是您的类库不是专门为UWP设计的,因此您无法尝试在那里获取资源。

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

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