无废话WPF系列18:控件模版
2011-02-27 11:15 敏捷的水 阅读(1141) 评论(0) 收藏 举报控件模版ControlTemplate就是设置控件的外观,比如我们常见到的按钮是下面这样的,但是我们如何改变成圆形的呢?
<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
版权:本文版权归作者所有,转载需经作者同意。
出处:http://www.cnblogs.com/cnblogsfans
版权:本文版权归作者所有,转载需经作者同意。


浙公网安备 33010602011771号