<Window.Resources>
<ControlTemplate x:Key="btntemp" TargetType="Button">
<Grid>
<Border Background="{TemplateBinding Background }" BorderBrush="Red" BorderThickness="5"/>
<ContentPresenter Content="{TemplateBinding Content }" ></ContentPresenter>
</Grid>
</ControlTemplate>
</Window.Resources>
可以看出来,我对控件模板的理解就是,将复杂的自定义控件抽象出来,通过绑定的方式来给与自己需要的样子,处处可用
<Window.Resources>
<ControlTemplate x:Key="btntemp" TargetType="Button">
<Grid>----------------------------------------------------------------------------用grid 是因为这玩意只能接受单一控件
<Border Background="{TemplateBinding Background }" BorderBrush="Red" BorderThickness="5"/>
<ContentPresenter Content="{TemplateBinding Content }" ></ContentPresenter>
</Grid>
</ControlTemplate>
</Window.Resources>