locked
XAML Resource Dictionary Pack URI RRS feed

  • Question

  • I have come across a problem using the pack uri syntax.

    I have a WPF application with an App.XAML. I use the pack uri syntax to reference dictionaries in other assemblies. This works fine for me.

    Now, I am trying to reference a dictionary located in a Class library from another Class library.

    Here is how the projects are being referenced. Application -> Class library 1 -> Class Library 2.

    references from App.xaml to Class library 1 work. However, references from Class library 1 dictionary to Class library 2 dictionary fail. I get the message that 'cannot locate resourcedictionary.xaml'.

    Has anyone tried doing this? I can post some sample code if the scenario is not clear.

    Thanks for help.
    Wednesday, November 25, 2009 9:40 PM

Answers

  • Hello Nachiket,

      It seems that there is an issue.

      Here is a workaround. We can use the ComponentResourceKey

        WPF has special support for retrieving logical resources from another assembly via a markup extension called ComponentResourceKey.


      For example we can define the following resource in an assembly A.
     <SolidColorBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:MyClass},
                         ResourceId=MyClassBrush}">Yellow</SolidColorBrush>
     Here MyClass is a class at assembly A.

    We can use it from assembly B which refers A.
      xmlns:reflib="clr-namespace:ReferredAssembly;assembly=ReferredAssembly">
    
    
    <Button 
             Background= "{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type reflib:MyClass},ResourceId=MyClassBrush}}" />
     More about ComponentResourceKey in 

       http://msdn.microsoft.com/en-us/library/ms753186.aspx
         
       
      If you have any question please let me know.

    Thanks.
    Friday, November 27, 2009 8:53 AM

All replies

  • Hello Nachiket,

      It seems that there is an issue.

      Here is a workaround. We can use the ComponentResourceKey

        WPF has special support for retrieving logical resources from another assembly via a markup extension called ComponentResourceKey.


      For example we can define the following resource in an assembly A.
     <SolidColorBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:MyClass},
                         ResourceId=MyClassBrush}">Yellow</SolidColorBrush>
     Here MyClass is a class at assembly A.

    We can use it from assembly B which refers A.
      xmlns:reflib="clr-namespace:ReferredAssembly;assembly=ReferredAssembly">
    
    
    <Button 
             Background= "{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type reflib:MyClass},ResourceId=MyClassBrush}}" />
     More about ComponentResourceKey in 

       http://msdn.microsoft.com/en-us/library/ms753186.aspx
         
       
      If you have any question please let me know.

    Thanks.
    Friday, November 27, 2009 8:53 AM
  • Thanks for your reply. I am still not sure how to resolve my problem though. I went over the suggested link on MSDN.

    Again the project structure is App -> class library 1 -> class library 2

    Class library 1 and class library 2 have a resource dictionary in each one of them. I am trying to merge class library 2's dictionary in class library 1's dictionary. App.xml in the main application project merges class library 1's dictionary. This way, I can just merge class library 1's dictionary throughout the app in windows and such and have access to class library 2's resources.

    I appreciate all your help. I can post a sample project here is you need me to.

    Thanks,

    Nachiket
    Tuesday, December 1, 2009 4:37 PM