In my WinUI 3 application, I am trying to use a ResourceDictionary that is located in another project.
Lets say the referenced project is ResourceTestLib
and this library project has a folder "Styles" which has a file "_Thickness.xaml".
In the app.xaml
file of the main application, I tried these two approaches below the "Other merged dictionaries here" comment, but none of them seem to work, i.e. that app crashes on startup with that message "Cannot locate resource ...." message.
This is my app.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
<ResourceDictionary Source="/ResourceTestLib;component/Styles/_Thickness.xaml"/>
<ResourceDictionary Source="pack://application:,,,/ResourceTestLib;component/Styles/_Thickness.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
When I hover over the respective line, Visual Studio shows a tooltip with "Path X not found" for the first referenced ResourceDictionary
and a "Invalid characters in path" (probably because of "application:,,,") message for the second.
I suppose that that WinUI XAML might be different than WPF XAML in that respect? Or even that this is not supported yet?
CodePudding user response:
Pack URIs are only used in WPF.
UWP and Win UI use the ms-appx URI scheme to refer to a file that resides in another assembly so try this:
<ResourceDictionary Source="ms-appx:///ResourceTestLib/Styles/_Thickness.xaml" />
More on UWP style URI schemes:
https://docs.microsoft.com/en-us/windows/uwp/app-resources/uri-schemes