随笔 - 12  文章 - 129  评论 - 11  阅读 - 76206

定制控件结构(controltemplate)

   在app.xaml页面中写样式,形式如下代码:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="SilverlightApplication2.App">
 <Application.Resources>
        <Style TargetType="Button" x:Key="RoundButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid x:Name="Root">
                            <Ellipse Width="240" Height="120">
                                <Ellipse.Fill>
                                    <RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5">
                                        <GradientStop Offset="0.2" Color="#FFFFFF"/>
                                        <GradientStop Offset="1" Color="#EC04FA"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <TextBlock Text="提交" FontSize="26" Foreground="Black" HorizontalAlignment="Center"></TextBlock>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Application.Resources>
</Application>

在布局页面这么写:
    <UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="SilverlightApplication2.Page"
 Width="640" Height="480">
        <Grid x:Name="LayoutRoot" Background="White">
        <Button Height="120" Width="120" Margin="236,0,277,123" VerticalAlignment="Bottom" Content="按钮" x:Name="btn" Click="btn_Click" Style="{StaticResource RoundButton}"/>
     </Grid>
</UserControl>
posted on   晴天1848  阅读(223)  评论(0编辑  收藏  举报
努力加载评论中...

点击右上角即可分享
微信分享提示