title: Is there any way to use StaticResource in a WPF control library and be able to view at design-time?
body: <p>I have a WPF Control Library that is being added to a windows forms application. We want to allow the controls to be localizable, however I am not sure how to FULLY accomplish this without duplicating code. <a href="https://stackoverflow.com/questions/4326621/wpf-control-not-displaying-in-elementhost-in-winforms-app">This is what I am doing now</a>.</p>
  
  <p>Basically, in the windows forms app, before the main application kicks off, I am instantiating an App.xaml that live within the forms app (containing my links to my resources that also live within the forms app). This works perfectly for runtime.</p>
  
  <p>However, my user controls all have <code>Content="{StaticResource SomeVariableName}"</code>, which end up being blank. I can fix this by having an app.xaml and appropriate resource dictionaries in my control library that match those in my windows forms app. However, this is duplicated code.</p>
  
  <p>Things I have already tried to no avail:</p>
  
  <ul>
  <li>Instantiate the App.xaml that lives within the user control library from within my forms app. This does not work because the URIs to my resources is looking for an embedded resource, not my local resource dictionary (I could then simply copy the resource files from the control to an appropriate location within my forms app on build). Could I leverage <a href="http://msdn.microsoft.com/en-us/library/system.windows.resourcedictionary.deferrablecontent.aspx" rel="nofollow noreferrer">DeferrableContent</a> here? There is not much online as far as I could find on this attribute and how it should be used, though.</li>
  <li>I would like to use post builds for both App and dictionaries, however, the App instantiation is a static reference to a compiled App.xaml as far as I can tell. So, App.xaml must live within the form at least
  
  <ul>
  <li>I did try to have a duplicated App.xaml with a post build moving the resourcedictionary.xaml. I figured that a duplicated app.xaml is ok since that is the driving force and you might not want to rely on one from the control anyway (which circles back and makes you wonder if you should then have the App.xaml in the control at all? Unless you want to allow a default that uses embedded resources....) That too failed saying it could not find the resource even though it was placed where the URI should have been pointing to. The decompiled code points to <code>Uri resourceLocater = new Uri("/WindowsFormsApplication3;component/app.xaml", UriKind.Relative);</code></li>
  </ul></li>
  </ul>
  
  <p>So, Is there any way to allow for this to work AND have design time viewing of the component defaults AND avoid duplication? Or, is the duplication OK in this case? If my 2nd bullet's sub-item seems ok (duplicated App.xaml with build copied resourcedictionaries), how do I make it not look for a component level item, but instead a file level one?</p>
  
  <p>Last question (and I can post this separately if necessary) that I just paid attention to. My App.xaml is being built into the code, so that does not allow me to create new ResourceDictionaries on the fly anyway. Is there any way to do this?</p>
  
  <p><strong>Final option...possibly the best one?</strong>
  - <a href="https://stackoverflow.com/questions/814600/multilanguage-in-wpf">I plan on using Andre van Heerwaarde's code anyway</a>, so should I just check for the existence of a file and add it as a merged resource on the fly? Basically, have one App.xaml in my user control that links to a default embedded ResourceDictionary. And, then have the code look for the appropriate localized resources on the fly, which can be relative file paths? The only downside I see here is that the default cannot be changed on the fly...which I could probably even have that look in a specified place (using some sort of convention) and have that preferred over the built-in one?</p>
  
  <p>Oh, and my reason for not wanting embedded resources is so that end users can add/modify new localized resources after the build is deployed.</p>
  
  <p>I can add code if it will help you visualize this better, just let me know.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I am now running into a further problem with styling and not just localizing.</p>
  
  <p>Here is an example of one of the internal buttons on one of the controls:</p>
  
  <pre><code>&lt;Button Style="{StaticResource GrayButton}"
  </code></pre>
  
  <p>Some more things I tried/thought:</p>
  
  <ul>
  <li>I cannot create an app.xaml (that would never be used) with the ResourceDictionary set up as ApplicationDefinitions are not allowed in library projects. I could embed this in the control's resources, but then that would always take precedence over any application level resources and I lose customizability.</li>
  </ul>
  
  <p><a href="https://stackoverflow.com/questions/4326621/wpf-control-not-displaying-in-elementhost-in-winforms-app">Here is a connect case</a> that actually sounds like what I am looking for, however it does not provide any real solution to this</p>
  
  <p>The solution (beyond the top..which does not work) that I can think of that might work (and have yet to try) also seems like a lot of work for something that I would think should be simple. But, I might be able to create some dependency properties in the control that I can Bind to and then allow those to be overriden by the project that will be using the control. As I said, that seems like a lot of work for a pretty simple request :). Would this even work? And more importantly, is there a better, simpler solution that I am missing?</p>