控件模版ControlTemplate就是设置控件的外观,比如我们常见到的按钮是下面这样的,但是我们如何改变成圆形的呢?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<
Window
x:Class="DeepXAML.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DeepXAML"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="250" Width="450">
<
Window.Resources
>
<
Style
x:Key="roundButton" TargetType="Button">
<
Setter
Property="Background">
<
Setter.Value
>
<
LinearGradientBrush
StartPoint="0.5,0" EndPoint="0.5,1">
<
LinearGradientBrush.GradientStops
>
<
GradientStop
Offset="0.0" Color="#fff" />
<
GradientStop
Offset="1.0" Color="Red" />
</
LinearGradientBrush.GradientStops
>
</
LinearGradientBrush
>
</
Setter.Value
>
</
Setter
>
<
Setter
Property="Template">
<
Setter.Value
>
<
ControlTemplate
TargetType="Button">
<
Grid
>
<
Ellipse
Fill="{TemplateBinding Background}"></
Ellipse
>
<
ContentPresenter
Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" /> </
Grid
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
Window.Resources
>
<
StackPanel
x:Name="stackPanel">
<
Button
Width="200" Height="120" Margin="20" Style="{StaticResource ResourceKey=roundButton}">OK</
Button
>
</
StackPanel
>
</
Window
>
|
ItemsControl有个PanelTemplate可以控制ItemsControl的条目容器。
本文转自敏捷的水博客园博客,原文链接http://www.cnblogs.com/cnblogsfans/archive/2011/02/27/1966176.html如需转载请自行联系原作者
王德水