Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use StaticResource in XAML root element

Tags:

wpf

xaml

I want to use StaticResource in the root element of a xaml document. But MSDN says:

Static resource references from within a resource dictionary must reference a resource that has already been defined lexically before the resource reference. Forward references cannot be resolved by a static resource reference.

And this:

The lookup process then traverses the logical tree upward, to the parent element and its resource dictionary. This continues until the root element is reached.

Should I define my resource in the application or create it from code?

like image 326
naeron84 Avatar asked Mar 03 '10 12:03

naeron84


1 Answers

If you really need to access a ResourceDictionary from the root element, you may be able to reference it as a DynamicResource rather than a StaticResource - I'm not sure if it will work, but it could be worth a try.

like image 102
TabbyCool Avatar answered Sep 20 '22 15:09

TabbyCool