Use {x:Type} with WPF Implicit DataTemplates

I have burned myself with this little thing so many times, I’m long overdue for a simple blog post as a reminder to myself for the future.

When you use Implicit DataTemplates in WPF, you need to specify the DataType property using the {x:Type} markup extension. In Silverlight and later XAML technologies that support implicit DataTemplates this changed because there was no x:Type markup extension, you just specified the type like so.

<DataTemplateDataType="local:ExplicitDataTemplatesViewModel"><local:ExplicitDataTemplatesView/>DataTemplate>

But in WPF it needs to look like this:

<DataTemplateDataType="{x:Type local:ExplicitDataTemplatesViewModel}"><local:ExplicitDataTemplatesView/>DataTemplate>

Otherwise, the data templates won’t match up. Now that I have written this maybe I will never burn myself with this stupid little thing again….