0

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:

enter image description here

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 ResourceDictionary in a separate assembly but that question was about WPF rather than UWP and doesn't seem to work

DTynewydd
  • 310
  • 4
  • 10

2 Answers2

1

I am not sure which category of URI schemes applies to such case but the following pattern should work.

<ResourceDictionary Source="ms-appx:///[library name]/Dictionary1.xaml"/>
emoacht
  • 2,764
  • 1
  • 13
  • 24
1

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.

Junjie Zhu - MSFT
  • 2,086
  • 1
  • 2
  • 6