The code you posted is not necessary. In your example, you strictly specified the content template: you explicitly used {StaticResource WorkspacesTemplate} , and therefore the resource with the key "WorkspacesTemplate viewed.
Since you explicitly defined the template, it does not matter what the assigned type is: it will try to display any object in your Content using the template that you installed, with varying degrees of success, if you use a type that does not match!
In the alternative method that you mentioned - using the "typed DataTemplate", you must declare your datatemplate using <DataTemplate DataType="{x:Type l:WorkSpace}" /> . Note that there is no x:Key (and also I assumed that you have a namespace l mapped to your local code). What happens here is that WPF automatically sets your resource key to DataType (itβs important to note: the resource key does not have to be a string!).
Then, when you declare your HeaderedContentControl , you can leave the ContentTemplate setting. At run time, when the control is displayed, WPF checks the type of the Content object and finds that it is WorkSpace , and then it searches for the resource with x:Key="{x:Type l:WorkSpace}" - which will match your typed template.
This is a useful way to create consistent representations of data throughout the application, since a typed DataTemplate will be automatically used by any content presentation control in your application.
source share