locked
What is: ContentTemplate="{TemplateBinding ContentTemplate}" RRS feed

  • Question

  • What does this line do?

    ContentTemplate="{TemplateBinding ContentTemplate}"

    I've seen it arround but I was a bit puzzled by it's purpose.

    Thanks,

    Thursday, January 28, 2010 9:53 PM

Answers

  •  It is typically found on a ContentPresenter in a ControlTemplate and I believe it is intended to ensure that a ContentTemplate set on the Control using the ControlTemplate is applied to the Content.

    Having said that I've just tried removing this from a copy of the standard Button ControlTemplate for a Button with a custom ContentTemplate and it still used the custom ContentTemplate. I would have expected it to not display the content at all.  Can anyone shed any light on this?

    Friday, January 29, 2010 8:21 AM
  • ContentPresenter has his Content and ContentTemplate properties defaulted to behave like a TemplateBinding on Content and ContentTemplate. So if you make a template for a ContentControl or derived (such as button), putting a ContentPresenter without setting its Content / ContentTemplate will do the same as explicitly declaring template bindings.

    For info, TemplateBindings are special bindings usable only in ControlTemplates (no DataTemplates), whose binding source is the control instance on which the template is applied.

    Friday, January 29, 2010 8:53 AM

All replies

  •  It is typically found on a ContentPresenter in a ControlTemplate and I believe it is intended to ensure that a ContentTemplate set on the Control using the ControlTemplate is applied to the Content.

    Having said that I've just tried removing this from a copy of the standard Button ControlTemplate for a Button with a custom ContentTemplate and it still used the custom ContentTemplate. I would have expected it to not display the content at all.  Can anyone shed any light on this?

    Friday, January 29, 2010 8:21 AM
  • ContentPresenter has his Content and ContentTemplate properties defaulted to behave like a TemplateBinding on Content and ContentTemplate. So if you make a template for a ContentControl or derived (such as button), putting a ContentPresenter without setting its Content / ContentTemplate will do the same as explicitly declaring template bindings.

    For info, TemplateBindings are special bindings usable only in ControlTemplates (no DataTemplates), whose binding source is the control instance on which the template is applied.

    Friday, January 29, 2010 8:53 AM