It's a bit hard to answer this question authoritatively without knowing a little more context, such as what type of file you are placing this in, and what the exact error is from Visual Studio. I imagine that you're getting an error such as:
The type 'ControlTemplate' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
or possibly:
Property 'Content' does not support values of type 'ControlTemplate'
These are caused by placing the template in the wrong place - for example, if you create a new UserControl
(via Add -> New Item) and delete the contents of the file and paste in your code, then you will get this error, since the xaml has no references to ControlTemplate
.
The best place to put your ControlTemplate
is somewhere reusable, such as a new "Resource Dictionary" (again, add it via Add -> New Item -> Silverlight Resource Dictionary) and then place your code inside the <ResourceDictionary ...></ResourceDictionary>
tags.
If you want to place it within a UserControl
(the source of the second error) then you should add it to the Resources
section of that control, for example:
<UserControl.Resources>
<ControlTemplate x:Key="ImageButtonTemplate">
<Image Source="{TemplateBinding Content}" />
</ControlTemplate>
</UserControl.Resources>