WPF DataTemplate access to Resources within same ResourceDictionary -


simplified, have resourcedictionary contains datatemplate , viewmodel-class.

<resourcedictionary>     <datatemplate datatype="whatever">         <listbox itemssource="{binding source={staticresource myviewmodel}, path=someglobaldata}" />     </datatemplate>      <myviewmodelclass x:key="myviewmodel" /> </resourcedictionary> 

of course binding won't work (it'll fire exceptions) because datatype won't have resource 'myviewmodel'. in visualtree "thing" gets datatemplated child of object has resourcedictionary merged resources, there might way access within runtime.

so question is: there clean way access 'myviewmodel' within datatemplate?

your problem order these resources instantiated , fact use staticresource vs dynamicresource.

a staticresource provides value xaml property attribute looking reference defined resource. try find out more on subject.

so please move view model above data template if still plan on using staticresource.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -