Is there a way to load xaml resources from a separate project?
Posted: 04 Jan 2019, 21:28
Starting with the HelloWorld C# example, I see that XAML resources are stored in the .resx file and loaded like this:
I created a new C# class library project "Modules.FileManager" and defined a UserControl based view there called "FileManagerView.xaml". I would like load that view into the MainWindow.xaml of the HelloWorld project like this:
... but that is crashing because FileManagerView.xaml is undefined (because I added it to a separate resource file, one defined in the Modules.FileManager project, rather than the HelloWorld project.
I assume I need to have FileMangerView.xaml loaded into a resource file?
Do all the xaml resources have to be in the same resource file or can they be defined in separate resources files in each class library project and then merged together somehow?
Code: Select all
public partial class App : Application
{
#if NOESIS
protected override XamlProvider GetXamlProvider()
{
EmbeddedXaml[] xamls =
{
new EmbeddedXaml { filename = "App.xaml", resource = "App" },
new EmbeddedXaml { filename = "MainWindow.xaml", resource = "MainWindow" },
};
return new EmbeddedXamlProvider(xamls, Properties.Resources.ResourceManager);
}
#endif
}
Code: Select all
<Window>
xmlns:fm="clr-namespace:Modules.FileManager;assembly=Modules.FileManager"
...
</Window>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Modules.FileManager;component/Resources/FileManagerView.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
...
<fm:FileManagerView></fm:FileManagerView>
...
I assume I need to have FileMangerView.xaml loaded into a resource file?
Do all the xaml resources have to be in the same resource file or can they be defined in separate resources files in each class library project and then merged together somehow?