英文:
How to access a resource dictionary contained in a referenced UWP Class Library?
问题
我正在尝试为UWP应用程序实现一个组件库的想法。
我遇到的一个问题是如何从主应用程序中访问组件库中的资源库中的资源。
这是我的测试应用程序的解决方案布局:
因此,MainPage.Xaml 包含一个 TemplatedControl
的实例,我想为它提供位于资源字典 Dictionary1
中的样式 (TemplatedControlStyle
)。
我该如何做?
我尝试过这里的示例:https://stackoverflow.com/questions/338056/resourcedictionary-in-a-separate-assembly 但是那个问题是关于WPF而不是UWP,并且似乎不起作用。
英文:
I'm playing around with the idea of implementing a component library for a UWP app.
One thing I'm struggling with is accessing resources from resource libraries in the component library from within the main application.
Here's the solution layout for my test application:
So MainPage.Xaml contains an instance of TemplatedControl
and I want to give the style (TemplatedControlStyle
) which is contained in the resource dictionary Dictionary1
.
How would I go about doing it?
I've had a go with the examples from here https://stackoverflow.com/questions/338056/resourcedictionary-in-a-separate-assembly but that question was about WPF rather than UWP and doesn't seem to work
答案1
得分: 1
以下是翻译好的部分:
"我不确定哪种URI方案适用于这种情况,但以下模式应该有效。
<ResourceDictionary Source="ms-appx:///[library name]/Dictionary1.xaml"/>
```"
<details>
<summary>英文:</summary>
I am not sure which category of [URI schemes](https://learn.microsoft.com/en-us/windows/uwp/app-resources/uri-schemes) applies to such case but the following pattern should work.
```xaml
<ResourceDictionary Source="ms-appx:///[library name]/Dictionary1.xaml"/>
答案2
得分: 1
我使用与你相同的框架创建了一个项目。我使用并验证了以下两种方法,它们可以访问组件库中的资源文件。
<ResourceDictionary Source="ComponentLibraryTest.Components/Dictionary1.xaml" />
<ResourceDictionary Source="ms-appx:///ComponentLibraryTest.Components/Dictionary1.xaml" />
顺便说一句,不要忘记将 "ComponentLibraryTest.Components" 添加到你的主项目的引用中。
英文:
I created a project with the same framework as yours. I used and verified the following two methods, and they can access the resource files in the component library.
<ResourceDictionary Source="ComponentLibraryTest.Components/Dictionary1.xaml" />
<ResourceDictionary Source="ms-appx:///ComponentLibraryTest.Components/Dictionary1.xaml" />
By the way, don't forget to add "ComponentLibraryTest.Components" into your main project's References.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论