Consider the case where I create a library MyCustomControlsProject
containing a set of custom controls. Instead of placing the XAML code for all those controls in a very large generic.xaml I want to separate each control in its own XAML file and then reference that file from generic.xaml
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="<url_syntax_file_1>" />
<ResourceDictionary Source="<url_syntax_file_2>" />
</ResourceDictionary.MergedDictionaries>
The folder structure in the solution explorer (as well as on the file system) looks like this:
- MyCustomControlsProject (project/folder)
- Themes (folder)
- Generic.xaml (file)
- ControlTemplates (folder)
- MyControl1.xaml (file)
- MyControl2.xaml (file)
- Themes (folder)
In the past, I did this in Silverlight and in Silverlight for Win Phone using this syntax:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyCustomControlsProject;Component/Themes/ControlTemplates/MyControl1.xaml"/>
<ResourceDictionary Source="/MyCustomControlsProject;Component/Themes/ControlTemplates/MyControl2.xaml"/>
</ResourceDictionary.MergedDictionaries>
And for Windows Phone 8.1 using this syntax:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Themes/ControlTemplates/MyControl1.xaml" />
<ResourceDictionary Source="ms-appx:///Themes/ControlTemplates/MyControl2.xaml" />
</ResourceDictionary.MergedDictionaries>
Neither of these syntaxes works in Win 10 (UWP). Attempting to use those leads to a run time exception:
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in MyApplication.exe but was not handled in user code
WinRT information: Failed to assign to property 'Windows.UI.Xaml.ResourceDictionary.Source' because the type 'Windows.Foundation.String' cannot be assigned to the type 'Windows.Foundation.Uri'.
I also tried this syntax that resulted in the same exception:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ControlTemplates/MyControl1.xaml" />
<ResourceDictionary Source="ControlTemplates/MyControl2.xaml" />
</ResourceDictionary.MergedDictionaries>
Interestingly enough it seems that app.xaml has no problems using the syntax above.
Does anyone know the correct syntax for the url string in a source
attribute in a ResourceDictionary
node in generic.xaml? Or is this something that UWP did not catch up with yet?
UserControl
in eachMyControl.xaml
file, or just data templates for controls? Or even data templates with bindings?