A
A
Artem Ivantsov2015-05-28 09:07:23
WPF
Artem Ivantsov, 2015-05-28 09:07:23

How to refer to a ResourceDictionary located in a DLL using a URI?

I have a DLL in it is ResourceDictionary SomeDict.xaml. There is also a static method inside which the dictionary is accessed.
There are two applications:
1. Console application
2. WPF
application These applications access the library's static method and directly access the resource dictionary themselves.
Everywhere used identical code for accessing dictionaries.

ResourceDictionary res = new ResourceDictionary();
            try
            {
                res.Source = new Uri("ClassLibrary1;component/SomeDict.xaml", UriKind.Relative);
                var l = res["SomeKey"];
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

Then I describe the situations and what came out of all this:
1. The WPF application works quietly with dll, the static method and the direct call are processed as it should.
2. The console application always gives the error "URI prefix not recognized".
How to make the second case work correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-05-28
@Ramirag

compilewith.net/2009/03/wpf-unit-testing-trouble-w...

A
Alexander Ryzhov, 2016-06-21
@RyzhovAlexandr

According to Stanislav's link, I decided like this

var uriSchemePack = PackUriHelper.UriSchemePack;
if (Application.Current == null)
{
    var application = new Application();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question