Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a ComponentResourceKey to Work?
    primarykey
    data
    text
    <p>I am building a WPF app with several assemblies, and I want to share a resource dictionary among them. That requires a <a href="http://books.google.com/books?id=XWu70Oqz6RIC&amp;pg=PA344&amp;lpg=PA344&amp;dq=wpf+&quot;sharing+resources+between+assemblies&quot;&amp;source=bl&amp;ots=FMQU9g3whX&amp;sig=rhK8YR-OUddEKmSBMqZXv45gxNc&amp;hl=en&amp;ei=JlqpSqf5NNKBtge6jqXYBw&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=1#v=onepage&amp;q=wpf%20%22sharing%20resources%20between%20assemblies%22&amp;f=false" rel="nofollow noreferrer">ComponentResourceKey</a>. I have built a small demo to test out the CRK, and I can't seem to get it working.</p> <p>My demo has two projects, a WPF project called <em>Demo</em>, and a DLL called <em>Common</em>. The <em>Common</em> project has a folder called <em>Themes</em>. It contains my resource dictionary, <em>generic.xaml</em>. Here is the text of the Resource dictionary:</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Common" &gt; &lt;SolidColorBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:SharedResources}, ResourceId=RedSolidBrush}" Color="Red"/&gt; &lt;/ResourceDictionary&gt; </code></pre> <p><em>Common</em> also contains a class called <em>SharedResources.cs</em>. It contains a property for referencing the Brush resource in the dictionary:</p> <pre><code>public static ComponentResourceKey RedSolidBrush { get { return new ComponentResourceKey(typeof (SharedResources), "RedSolidBrush"); } } </code></pre> <p>Finally, the main window in my <em>Demo</em> project references the brush resource to fill a rectangle:</p> <pre><code>&lt;Window x:Class="ComponentResourceKeyDemo.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:res="clr-namespace:Common;assembly=Common" Title="Window1" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;Rectangle Height="100" Width="100" Stroke="Black" Fill="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type res:SharedResources}, ResourceId=RedSolidBrush}}" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>I can't find the reason it's not working. It compiles fine in VS 2008 and Blend, but the resource isn't invoked. The only clue I have is an error message in Blend: </p> <pre><code>The Resource "{ComponentResourceKey ResourceId=RedSolidBrush, TypeInTargetAssembly={x:Type res:SharedResources}}" could not be resolved. </code></pre> <p>Any idea why this isn't working? Thanks for your help. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload