How can I access ResourceDictionary in wpf from C# code?

Since Application.Current was null in my case, I’ve ended up using this:

    var myResourceDictionary = new ResourceDictionary();
    myResourceDictionary.Source =
        new Uri("/DllName;component/Resources/MyResourceDictionary.xaml",
                UriKind.RelativeOrAbsolute);  

and then getting the specified key I needed by using
myResourceDictionary["KeyName"] as TypeOfItem

(source)

Leave a Comment