Select a data template by item type programatically in WPF
Posted
by Michael Stoll
on Stack Overflow
See other posts from Stack Overflow
or by Michael Stoll
Published on 2010-04-03T15:14:28Z
Indexed on
2010/04/03
15:23 UTC
Read the original article
Hit count: 266
wpf
|datatemplate
Hi all,
unfortunately the WPF ToolbarTray does not support binding to a collection of ToolbarViewModels (Correct me, if I'm wrong). Thus I want to create the Toolbars programmatically. So there are two tasks, which I don't know how to do:
- Select the data template based on the item type.
- Instantiate the data template as toolbar
Both should do the same as WPF does, when we use ItemsControl with an enumerable content and empty template.
I used reflector to anaylse what WPF does. Task 1 is done by FrameworkElement.FindTemplateResourceInternal, but this is internal, and I couldn't find any public methods to acomplish the task. Of course one could enumerate all resources and match the data template data type property, but this seems sub-optimal.
Who know's how to acomplish these tasks?
© Stack Overflow or respective owner