I’m building a WPF application where the Views are located in a separate project (e.g., MyApp.Views), while App.xaml is in the main project (MyApp). In App.xaml, I reference resources from the Views project, like this:
<Application x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyApp.Views;component/Resources/Icons.xaml" />
<ResourceDictionary Source="pack://application:,,,/MyApp.Views;component/Resources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
At runtime, everything works fine, but in design-time (when opening a UserControl in the designer), I get errors like: The resource “Some Icon” could not be resolved.
Project Structure:
- MyApp
Main project containing App.xaml. It references MyApp.Views. - MyApp.Views
Contains the UserControls, Resource dictionaries and everything else UI related.
Example UserControl:
<UserControl x:Class="MyApp.Views.AddressBarView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Button>
<Image Source="{StaticResource MyIcon}" />
</Button>
</Grid>
</UserControl>
My question is how can I configure my project so that resources from App.xaml are available in the Views (located in a separate project) during design-time?
So right now i use a temporary solution to this problem, i just add a resource to usercontrol, like this:
<UserControl.Resources>
<ResourceDictionary Source="/MyApp.Views;component/MyPathToResource/Icons.xaml" />
</UserControl.Resources>
And it works, but I don’t want to add to my every UserControl resource like that
Александр Крашенников is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.