Why doesn’t this work:
<Style TargetType="s:Substance">
<Setter Property="Template">
<Setter.Value>
<DataTemplate>
<StackPanel>
<TextBlock Text="{TemplateBinding Name}"/>
<TextBox Text="{TemplateBinding Count}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
If I switch to ControlTemplate it works, but I need a data template. Also, if I replace Template with DataTemplate it doesn’t recognize the property. Does anyone know what is going on? Thank you.
NOTE: Substance derives from FrameworkElement. It is not a control.
You don’t seem to know what you are doing,
Templateexpects aControlTemplate, this property sets the template of the control itself, not its data.Does your
Substancecontrol even have any property that expects aDataTemplate? e.g.ContentTemplate(if it is aContentControl) orItemTemplate(if it is anItemsControl)?Edit: You probably just want to do this:
Which defines a datatemplate for
Substance; WhereverSubstanceis added as content or item, that datatemplate will be automatically applied.