Ethan
Ethan

Reputation: 628

Reference ResourceDictionary from ViewModel

I have been trying to load a resource dictionary XAML file in my view model. I am able to instantiate it, and calls to it do not result in an immediate error, but after control returns to the UI, there is an error popup "Error HRESULT E_FAIL has been returned from a call to COM component".

I am doing the following:

Debugging shows that VMResources and Template1 are being assigned good values. I don't know why this would be throwing errors about COM components, but I have isolated it to when this ResourceDictionary is referenced. If I take out the lines referencing VMResources[x] there is no error. Any help would be much appreciated.

Upvotes: 1

Views: 1707

Answers (1)

Ethan
Ethan

Reputation: 628

Turns out this does work as I described, but you can't have events specified in the templates found in the resource dictionary. I should have realized that was going to cause problems, COM was throwing me off though. To get around the need for event handlers, I am using Behaviors. There's tons of reading out there on Behaviors. I started here and here.

note: If anyone believes I should delete this question since it actually works as proposed, just comment as so. I figure leaving this might help someone trying to do the same thing as me though.

Upvotes: 1

Related Questions