Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7844115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:46:33+00:00 2026-06-02T16:46:33+00:00

I have a WPF Control Library that is being added to a windows forms

  • 0

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. This is what I am doing now.

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.

However, my user controls all have Content="{StaticResource SomeVariableName}", 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.

Things I have already tried to no avail:

  • 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 DeferrableContent here? There is not much online as far as I could find on this attribute and how it should be used, though.
  • 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
    • 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 Uri resourceLocater = new Uri("/WindowsFormsApplication3;component/app.xaml", UriKind.Relative);

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?

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?

Final option…possibly the best one?
– I plan on using Andre van Heerwaarde’s code anyway, 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?

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.

I can add code if it will help you visualize this better, just let me know.

UPDATE

I am now running into a further problem with styling and not just localizing.

Here is an example of one of the internal buttons on one of the controls:

<Button Style="{StaticResource GrayButton}"

Some more things I tried/thought:

  • 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.

Here is a connect case that actually sounds like what I am looking for, however it does not provide any real solution to this

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:46:33+00:00Added an answer on June 2, 2026 at 4:46 pm

    I’ve run into this problem once, and I resolved it by dropping the whole “Resources are objects indexed by key in canonical dictionaries” thing.

    I mean, the simple fact of defining a resource in one project and referencing it in another by it’s “key” should give goosebumps to any sane person. I wanted strong references.

    My solution to this problem was to create a custom tool that converts my resource xaml files to static classes with a property for each resource:

    So MyResources.xaml:

    <ResourceDictionary>
      <SolidColorBrush x:Key="LightBrush" ... />
      <SolidColorBrush x:Key="DarkBrush" ... />
    </ResourceDictionary>
    

    Becomes MyResources.xaml.cs

    public static class MyResources {
    
      static MyResources() {
        // load the xaml file and assign values to static properties
      }
    
      public static SolidColorBrush LightBrush { get; set; }
      public static SolidColorBrush DarkBrush { get; set; }
    
    }
    

    For referencing a resource, you can use the x:Static instead of StaticResource:

    <Border 
       Fill="{x:Static MyResources.LightBrush}"
       BorderBrush="{x:Static MyResources.DarkBrush}"
       ... />
    

    Now you got strong references, autocompletion and compile time check of resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application that is using a WindowsFormsHost control to host a
I have a prism app where I've added a third party WPF control library
I have a control library that consists of only UserControl derived controls. I am
If you have a WPF control library which you wanted to license to developers,
I have a WPF control, that has a list of Investors, and in the
I have a custom WPF control that I made a couple of days ago:
I have a WPF User control that binds to a DataTable and generates CheckBox
I need the DocumentViewer WPF control (for XPS files) in a Windows Form application.
I have noticed that some WPF controls have some decent effects available to them
I am new to WPF and have created a WPF User Control Library I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.