.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > Adding a ResourceDictionary using a custom markup extension
 

Adding a ResourceDictionary using a custom markup extension

Hi. I have a markup extension that provides a ResourceDictionary:

public class CustomExtension : MarkupExtension
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var r = GetResourceDictionary();
            return r;
        }
    }
GetResourceDictionary() is a method that returns a valid ResourceDictionary object. I want to add this to my Application.Resources

<Application.Resources>
        <local:CustomExtension />
    </Application.Resources>
but this doesn't work. Why doesn't it?
Johnny Q.
You must add a ResourceDictionary to ResourceDictionary.MergedDictionaries. Window.Resources only has get accessor.
        <ResourceDictionary x:Key="rd">
            <ResourceDictionary.MergedDictionaries>
                <local:CustomExtension/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>


Bigsby, Lisboa, Portugal - O que for, quando for, é que será o que é... http://bigsby.eu
Bigsby
I tried that too, but it doesn't work either.
Johnny Q.

You can use google to search for other answers

Custom Search

More Threads

• WPF and Generics
• Transfer listbox items into listview by clicking Okbutton
• WPF MediaElement strange problem (bug)
• WPF Deployment - Framework redistributable size is huge
• MP3 Playback API
• How to develop a wpf application used MDI framework?
• How to get the value of other elements from an item in a ListBox using buttons?
• ListView/GridView and ObservableCollection
• Using the "Windows" key on the keyboard to minimize WPF windows ...
• Application resources are not recognized in window (VB 2008)