Bookmark and Share Share...    Subscribe to this feed Feed   About Christian Moser  


Application level resources & Windows Forms Integration

Download sample


When WPF is hosted in a Windows Forms application, you don't have a App.xaml. The question is, where to place application wide resources?

The answer is quite simple. Just manually create your own instance of an Application and merge the resources you want to have available on application level:

 
public Form1()
{
    InitializeComponent();
 
    // Create a WPF application 
    var app = new System.Windows.Application();
 
    // Load the ressources
    var resources = System.Windows.Application.LoadComponent(
        new Uri("Styles.xaml", UriKind.Relative)) 
        as System.Windows.ResourceDictionary
 
    // Merge it on application level
    app.Resources.MergedDictionaries.Add(resources);
}
 
 




Last modified: 2011-01-27 15:55:44
Copyright (c) by Christian Moser, 2011.

 Comments on this article

Show all comments
PPS
Commented on 2.March 2011
Quiet easy
Steve
Commented on 12.May 2011
Hi Christian - It's clear from this about how to load Resources, but we also have a bunch of value converters in our app.xaml that winforms doesn't seem to recognize. Is there some way similar to this to tell winforms about the value converters that are in a separate library? Thanks in advance!

Name
E-Mail (optional)
Comment