What is the correct syntax for splitting a generic.xaml file using MergedDictionaries (UWP)

Consider the case when I create a library MyCustomControlsProjectcontaining a set of custom controls. Instead of putting the XAML code for all of these controls in a very large generic.xaml, I want to separate each control in my 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 in the file system) is as follows:

  • MyCustomControlsProject (project / folder)
    • Themes (folder)
      • Generic.xaml (file)
      • ControlTemplates (folder)
        • MyControl1.xaml (file)
        • MyControl2.xaml (file)

In the past, I have done this in Silverlight and 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>

Windows Phone 8.1 :

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ms-appx:///Themes/ControlTemplates/MyControl1.xaml" />
    <ResourceDictionary Source="ms-appx:///Themes/ControlTemplates/MyControl2.xaml" />
</ResourceDictionary.MergedDictionaries>

Win 10 (UWP). :

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'.

, :

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ControlTemplates/MyControl1.xaml" />
    <ResourceDictionary Source="ControlTemplates/MyControl2.xaml" />
</ResourceDictionary.MergedDictionaries>

, app.xaml .

- url source ResourceDictionary node generic.xaml? , UWP ?

+4
2

:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="ms-appx:///MyCustomControlsProject/Themes/ControlTemplates/MyControl1.xaml" />
    <ResourceDictionary Source="ms-appx:///MyCustomControlsProject/Themes/ControlTemplates/MyControl2.xaml" />
</ResourceDictionary.MergedDictionaries>
+4

"" :

<ResourceDictionary>  
  <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Themes/ControlTemplates/MyControl1.xaml" />
        <ResourceDictionary Source="Themes/ControlTemplates/MyControl2.xaml" />
    </ResourceDictionary.MergedDictionaries>
   </ResourceDictionary>
0

Source: https://habr.com/ru/post/1612877/


All Articles