hahacjh
既然选择了远方 便只顾风雨兼程

1.在控件声明中直接定义;

 

<Button Content="Button1">
<Button.Template>
<ControlTemplate TargetType=“Button”>
<!--在此ControlTemplate‐‐>
</ControlTemplate>
</Button.Template>
</Button>


2.在容器的资源属性中定义:

 

代码
<StackPanel>
<StackPanel.Resources>
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<!‐‐在此定义ControlTemplate ‐‐>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<Button Style="{StaticResource ButtonStyle}" Content="Button1"/>
</StackPanel>

 

 

 

3.app.xaml文件中定义:

代码
<Application.Resources>
<Style TargetType="TextBlock" x:Key="TextBlockPrompt">
<Setter Property="VerticalAlignment" Value="Bottom" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="FontFamily" Value="Verdana" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Medium" />
<Setter Property="Foreground" Value="Blue" />
</Style>
</Application.Resources>

 

前段绑定方法:

<Button Style="{StaticResource TextBlockPrompt}" Content="Button1"/>

 

posted on 2010-02-28 12:17  hahacjh  阅读(669)  评论(0编辑  收藏  举报