In a WPF (.NET Core) application project I have defined a folder to contain all custom controls (both class definitions and UI style .xaml files, each custom control has a pair of these files). When using these custom controls in the same assembly, I associate the default style to the custom control by merging all UI styles in the /Themes/Generic.xaml shown below
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/CustomControl/SomeCustomControlStyle.xaml" />
<!-- Similarly list all other custom control xaml files -->
</ResourceDictionary.MergedDictionaries>
For each custom control the corresponding xaml defines its style without x:Key as follows
<Style TargetType="{x:Type SomeCustomControl}" >
<Setter Parameter="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type SomeCustomControl}">
<!-- UI Definitions -->
</<ControlTemplate>
</Setter.Value>
</Setter>
</Style>
All custom control derives from Control and contains a static constructor with
DefaultStyleKeyProperty.OverrideMetadata(typeof(SomeCustomControl),
new FrameworkPropertyMetadata(typeof(SomeCustomControl)));
The project build successfully and the custom controls are shown when application is running. However Visual Studio designer is unable to display any custom controls and reporting an error
XDG0062 Cannot locate resource 'customcontrols/somecustomcontrol.xaml'.
I have tried to move the default style from individual .xaml files to Generic.xaml and the problem can be solved. However I have quite a few custom controls and using a single Generic.xaml to define all the UI is not very ideal. But not be able to see UI elements in designer is also very inconvenient. Am I missing something? Is it a Visual Studio bug? Are there any walkarounds?
Thanks!