ResourceDictionary in a separate library

I defined myDictionary resource in a separate library as shown below

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cultures="clr-namespace:My_Localization.Cultures" xmlns:properties="clr-namespace:My_Localization.Properties"> <ObjectDataProvider x:Key="Resources" ObjectType="{x:Type cultures:CultureResources}" MethodName="GetResourceInstance"/> <ObjectDataProvider x:Key="CultureResourcesDS" ObjectType="{x:Type cultures:CultureResources}"/> </ResourceDictionary> 

I used this library from another library as shown below (header for xaml only)

 <msRibbon:RibbonTab x:Class="Ribbon.Planner.PlannerRibbon" 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" xmlns:msRibbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="500" Header="{Binding Path=Ribbon_About, Source={StaticResource Resources}}" > <Grid> ... ... ... </Grid> 

I added the link My_Localization lib and change only the title. Everything works fine, but the only problem is that during development I have "Header =" {Binding Path = Ribbon_About, Source = {StaticResource Resources}} "underlined. When I hovered over the" Resources "tooltip could not be resolved "

Why is there a error like hint in my haml? and then why does all this work fine?

Structure of my decision

  • MainExe - Contains app.xaml. Here I have combined the resource dictionary. No problem in xaml as merge dictionary exists in app.xaml
  • My_Localization - Lib containing the resource dictionary (code above)
  • Lib1 - My_Localization links and there are problems in xaml as described
  • Lib2 - My_Localization links and there are problems in xaml as described
  • Lib3 - My_Localization links and there are problems in xaml as described
0
c # wpf xaml
source share
3 answers

You need to specify a link to the ResourceDictionary in the app.xaml file or locally. Resources in app.xaml are available globally for all application app.xaml files.

For Xaml files in library projects, the designer works a little differently.

At run time, the launch project will have app.xaml , which will be used for all builds. At the time of design, this will be the local build app.xaml . This means that you can add the app.xaml file to libraies, which will only be used by Visual Studio Designer when rendering xaml files from this particular library (Set build action of the file to Page).

To reference a ResourceDictionary do the following:

 <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Application.Resources> <ResourceDictionary> <!-- Other global resources --> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/ASSEMBLYNAME;component/FOLDERPATH/RDNAME.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> 

Where ASSEMBLYNAME is the name of the assembly, where is ResourceDictionary (check project properties).

Example:

A project with the assembly name: "MyAssembly" and ResourceDictionary in the path to the "Resources / RDs / MyRd.xaml" folder

 Source="pack://application:,,,/MyAssembly;component/Resources/RDs/MyRd.xaml" 
+1
source share

You can include ResourceDictionary in every xaml

 <msRibbon:RibbonTab x:Class="Ribbon.Planner.PlannerRibbon" 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" xmlns:msRibbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="500" Header="{Binding Path=Ribbon_About, Source={StaticResource Resources}}"> <msRibbon:RibbonTab.Resources> <ResourceDictionary Source="pack://application:,,,/<ASSEMBLY_NAME>;component/<RESOURCES_FILE>.xaml"/> </msRibbon:RibbonTab.Resources> <Grid> ... ... ... </Grid> 
+1
source share

In App.xaml you must add MergedDictionary to resources that will reference your other dictionary.

 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/RibbonControlsLibrary;component/Your/Dictionary/Path.xaml" /> ... </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 
0
source share

All Articles