0

Everything happens within the same VS project. I have a resource dictionary file living on it's own. When I try to load it programmatically I get the error

"Cannot create unknown type '{clr-namespace:MyAssembly.Helpers}IsNullConverter".

Here is how I load it :

StreamResourceInfo stream = Application.GetResourceStream(new Uri(@"MyAssembly;component/Resources/Resources.xaml", UriKind.Relative));

this.dynamicResources = XamlReader.Load(stream.Stream) as ResourceDictionary;

And here is the resource dictionary :

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:helpers="clr-namespace:MyAssembly.Helpers">

<helpers:IsNullConverter x:Key="IsNullConverter" />

Styles go here...

Note that it is tied to a code-behind file, but there is nothing in it. The Build-Action of the resource file is set to "Resource". This is driving me crazy since this morning and still no clue what the heck is going on...

Help. Thank you.

1
  • Where is the MyAssembly.Helpers.IsNulLConverter defined? The parser is looking for the class under that supplied path and failing to find the expected metadata... Commented Sep 24, 2012 at 17:40

2 Answers 2

1

Halelujah I fugured it out. All I had to do is load the resource dictionary directly

Uri uri = new Uri(@MyAssembly;component/Resources/Resources.xaml", UriKind.Relative); this.dynamicResources.Source = uri;

And make sure Build Action of resource dictionary file is set to "Page"

\m/

Sign up to request clarification or add additional context in comments.

Comments

0

Is the assembly referenced by your project? If not try adding a reference - if you don't want a dependency you could try loading the assembly:

http://www.dreamincode.net/forums/topic/78974-using-reflection-to-load-unreferenced-assemblies-at-runtime/

Alternatively you could add a x:Class definition to the resourcedictionary, and instantiate the class from the assembly instead of loading the xaml, and remember to call the generated InitializeComponent() from the constructor, the it will load.

Is it possible to set code behind a resource dictionary in WPF for event handling?

Your example would work fine if the ResourceDictionary and converter was in the same assembly as where you load from, as far as I can see :)

1 Comment

Thanks for answering, but that did not solve the problem. I figured it out, I'll post the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.