此处是mainpage.xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel >
<Button x:Name="custombutton" Content="custom styled button"
Margin="10" Width="350" Height="350" BorderBrush="White"
BorderThickness="5"
Style="{StaticResource custombuttonstyle}"/>
<Button x:Name="standardbutton"
Content="standard button" Margin="10"/>
</StackPanel >
</Grid>
</Grid>
此处是app.xaml:
<Application.Resources>
<Style x:Key="custombuttonstyle" TargetType="Button" >
<Setter Property="Template" >
<Setter.Value >
<ControlTemplate>
<Border Width="{TemplateBinding width}"
Height="{TemplateBinding height}" BorderBrush="{TemplateBinding borderbrush}"
BorderThickness ="{TemplateBinding borderthickness}">
<StackPanel >
<Image Source="ApplicationIcon.png" Width="200" Height="300"/>
<TextBlock Text="{TemplateBinding content}" TextAlignment="Center" />
</StackPanel >
</Border >
</ControlTemplate >
</Setter.Value >
</Setter >
</Style >
</Application.Resources>
此处是mainpage.xaml.cs
namespace 控件模板
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
this.Loaded +=(s,e)=>
{
custombutton.Click +=
new RoutedEventHandler(custombutton_Click);
standardbutton.Click +=
new RoutedEventHandler(standardbutton_Click);