ComplexGroupDataTemplateSelector

The ComplexGroupDataTemplateSelector enhances how DataTemplates are found in your application. In addition to being able to specify data templates for IEnumerable collections, the ComplexGroupDataTemplateSelector will also find a template based on a interface implemented by the data item or a base type found in the data item hierarchy. Though data templates found in this manner are a little more expensive to perform than just a simple Type lookup, the ComplexGroupDataTemplateSelector caches it's resolutions to help reduce the overall performance impact. The template selector can be tuned for specific needs using a few properties.

DiscoveryMethod Property

The default setting for the DiscoveryMethod property is "Key, Type, Interface, Hierarchy"
The DiscoveryMethod is a enum flag property in which the following flags can be set:


Key Flag
Find the DataTemplate by creating a resource key using the string format expression found in TemplateKeyFormat or GroupTemplateKeyFormat.

Type Flag
Find the DataTemplate by looking up the item Type for a template with a matching DataType property. This is the default way the DataTempates are found without using the ComplexGroupDataTemplateSelector.

Interface Flag
Find the DataTemplate by looking up each interface implemented by the item type for a template with a matching DataType property.

Hierarchy Flag
Scan the item types type hierarchy to find the DataTemplate based on it's DataType property.

GeneralToSpecific Flag

FullTypeName Flag
Use the full type name when creating a resource key using the string format of either TemplateKeyFormat or GroupTemplateKeyFormat
If not set the unqualified type name will be used. The default is to use the unqualified type name.

For example:

When not set, the resource key created for type DaisleyHarrison.WPF.ComplexDataTemplates.UnitTest.ClassA would be data-template[ClassA]

When FullTypeName is set, the resource key created for type DaisleyHarrison.WPF.ComplexDataTemplates.UnitTest.ClassA would be data-template[DaisleyHarrison.WPF.ComplexDataTemplates.UnitTest.ClassA]

NoCache Flag
Does not cache the result of the resource search. Fources the DataTemplate to be looked up for each item. The default is to cache all DataTemplate lookups so that a DataTemplate is found only once for each unique item Type. This flag is used primarily for debugging.
Note: using this flag can impact performance.

TemplateKeyFormat Property

The TemplateKeyFormat property is the string format expression used to create a resource key for non-collection items. That is all items that do not implement the IEnumerable interface.

The default value for the TemplateKeyFormat property is "data-template[{0}]".

GroupTemplateKeyFormat Property

The GroupTemplateKeyFormat property is the string format expression used to create a resource key for all collection items. That is all items that implement the IEnumerable interface.

The default value for the TemplateKeyFormat property is "IEnumerable[{0}]".

Last edited Dec 1, 2008 at 3:16 AM by aarondh, version 14

Comments

No comments yet.