I have two datatemplates defined as static resources. Now I have a combobox with each of those names. Is it possible to have your controls utilizing these staticresources as itemtemplates to bind to the name of the selected static resource in the combobox?
Thanks in advance.
Here is something that looks quite insane but works reasonably well.
Resource dictionary is fundementally an collection of the
KeyValuePair<object, object>, except Xaml parsing gives use a leg up with populating it using thex:Keyattribute. So this ComboBox displays theKeyproperty but itsSelectedItemwill be theKeyValuePair<object, object>whoseValueproperty is theDataTemplatewe want. We can now use element to element binding on aContentTemplateor anItemTemplateproperty.If you also need the DataTemplates available as static resources and you want to avoid code duplication you can place them in a separate resource dictionary xaml file. You can then use:-
As well as include them in static resources like:-