PlainView will not load xaml page related to componentResourceKey and resourceid

340 views Asked by At

I have a external library to hold all themes in which i am defining a style for PlainViews. The plainview class that extends viewbase sits in another project. My app won't load the xaml for the plainview. it seems like it can't find the resourceid associated with the PlainView

Here's the xaml defining the plainview

<Style x:Key="{ComponentResourceKey 
        TypeInTargetAssembly={x:Type Common:PlainView},
        ResourceId= PlainViewRsx}" 
        TargetType="{x:Type ListView}" 
        BasedOn="{StaticResource {x:Type ListBox}}">
</Style>

the PlainView code behind is defined in another project.

1

There are 1 answers

0
lachi On

I'm not sure if i understand your proplem correctly (or even if you still have this problem), so i'm telling you my approach, I think i needed something similar:

  1. I have my themes in external assemblies (each theme is represented as a resource dictionary), which can be changed by exchanging the resource dictionaries of the class at runtime
  2. The keys to the resources are stored in another assembly
  3. Accessing the themes and the resources are again in a different assembly

First make sure that you have all the required references in all the needed projects.

The Class which stores the Keys:

public class CoreResourceKeys
{
      public static readonly string BrushMyBrush = "MyBrush";
      public static ComponentResourceKey Brush_MyBrush
      {
          get
          {
              return new ComponentResourceKey(typeof(CoreResourceKeys), CoreResourceKeys.BrushMyBrush);
          }
      }
}

My theme files looked something like this:

<ResourceDictionary xmlns=[...]
    xmlns:resources="clr-namespace:AssemblyThatStoresTheKeys;assembly=CoreResourceKeys">
    <SolidColorBrush x:Key="{ComponentResourceKey 
        TypeInTargetAssembly={x:Type resources:CoreResourceKeys}, 
        ResourceId={x:Static resources:CoreResourceKeys.BrushMyBrush}}"  
    Color="DarkMagenta"/>
</ResourceDictionary>

And the control/page whereever I wanted to use the brush looked like this:

<UserControl x:Class=[...] 
    xmlns:resources="clr-namespace:AssemblyThatStoresTheKeys;assembly=CoreResourceKeys">
    <TextBlock Background="{DynamicResource {x:Static resources:CoreResourceKeys.Brush_MyBrush}}" Text="The Shire"/>

that blog-post helped me quite a lot: MSDN Support Forum - Loading Styles from My Assembly

I'm not sure if that helps you. If not, please try to describe your problem in more details.