title: Assembly-wide / root-level styles in WPF class library
body: <p>I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on <a href="http://dotupdate.wordpress.com/2007/12/05/how-to-add-a-wpf-control-library-template-to-visual-c-express-2008/" rel="noreferrer">this article</a>).<br/> I've created several windows, and am now attempting to create a common style set for them. However, as it's a class library (instead of a WPF app), I don't have an app.xaml (and its contained Application &amp; corresponding Application.Resources) in which to store these styles for global access.</p>
  
  <p><strong>So:</strong> How can I create a top-level set of style definitions that'll be seen by all xaml files in the assembly, <em>given that I do not have app.xaml (see above)</em>? And/or is it possible to <em>add</em> a working app.xaml to a class library?</p>
  
  <p>FYI, I did try creating a ResourceDictionary in a ResourceDictionary.xaml file, and include it in each window within a "Window.Resources" block. That turned out to solve the styling of Buttons, etc... but not for the enclosing Window. I can put <code>Style="{StaticResource MyWindowStyle}"</code> in the Window's opening block, and it compiles and shows up in the VS Design window fine, but during actual runtime I get a parse exception (MyWindowStyle could not be found; I'm guessing Visual Studio sees the dictionary included after the line in question, but the CRL does things more sequentially and therefore hasn't loaded the ResourceDictionary yet).</p>
  
  <hr>
  
  <p>Thanks for the ideas, but still no go... apparently a class library does NOT support the generic.xaml usage implicitly. I added generic.xaml to my class library project and set its Build Action to "Resource". It contains:</p>
  
  <pre><code>&lt;ResourceDictionary 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Style TargetType="{x:Type Window}" x:Key="MyWindow"&gt;
          &lt;Setter Property="Background" Value="Black"/&gt;
      &lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>The window xaml that I want to have use the theme looks like this:</p>
  
  <pre><code>&lt;Window x:Class="MyAssembly.ConfigureGenericButtons"
      x:ClassModifier="internal"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Style="{StaticResource MyWindow}"
      Title="ConfigureGenericButtons"&gt;
  ...Buttons, etc...
  &lt;/Window&gt;
  </code></pre>
  
  <p>Although the VS Design window doesn't show the window using the MyWindow style (ie black background), it compiles fine and starts up. However, when the app containing this class library makes a call that causes this window to display, I get a XamlParseException:</p>
  
  <blockquote>
    <p>Cannot find resource named '{MyWindow}'.</p>
  </blockquote>
  
  <p>I also tried leaving out the Style parameter, to see if the window would use the style by default (and I tried that both with the x:Key in generic.xaml included and without). No errors, but anything defined in the generic.xaml didn't show up either.</p>
  
  <p>Am I doing something wrong here, or any other ideas on how one might allow for common custom styles to be used on a Window (ie, not have to define the styles in each Window's xaml) -- with the caveat that this is NOT an application?</p>