wpf 自定义控件之Button



1.学习wpf  一段时间,自己写了一个圆形Button 上传代码,菜鸟初级,大家勿见笑:

<Window.Resources>
        <GradientStopCollection x:Key="MyGlassGradientStopsResource">
            <GradientStop Color="White"
                          Offset="0.2" />
            <GradientStop Color="Transparent"
                          Offset="0.4" />
            <GradientStop Color="White"
                          Offset="0.5" />
            <GradientStop Color="Transparent"
                          Offset="0.75" />
            <GradientStop Color="White"
                          Offset="0.9" />
            <GradientStop Color="Transparent"
                          Offset="1.0" />
        </GradientStopCollection>

        <LinearGradientBrush x:Key="MyGlassBrushResource"
                             StartPoint="0,0"
                             EndPoint="1,1"
                             Opacity="1"
                             GradientStops="{StaticResource MyGlassGradientStopsResource}" />
        <ControlTemplate TargetType="Button"
                         x:Key="cirbtn">
            <!--<定义视觉树>-->
            <Grid>
                <Ellipse Opacity="1.0"
                         Fill="{TemplateBinding Button.Background}"
                         Width="{TemplateBinding Button.Width}"
                         Height="{TemplateBinding Control.Height}">
                </Ellipse>

                <Grid   Margin="15,15,15,15"
                        x:Name="cirgrid">
                    <Canvas x:Name="mycavas">
                        <Ellipse x:Name="innerel"
                                 Opacity="1"
                                 Fill="{StaticResource MyGlassBrushResource}"
                                 Width="{Binding ElementName=mycavas,Path=ActualWidth}"
                                 Height="{Binding ElementName=mycavas,Path=ActualHeight}"
                                 RenderTransformOrigin="0.5,0.5">
                            <Ellipse.RenderTransform>
                                <TransformGroup>
                                    <RotateTransform x:Name="cubeRotateTransform" />
                                </TransformGroup>
                            </Ellipse.RenderTransform>

                        </Ellipse>
                        <Ellipse x:Name="innerel2"
                                 Opacity="0.5"
                                 Fill="Red"
                                 Width="{Binding ElementName=mycavas,Path=ActualWidth}"
                                 Height="{Binding ElementName=mycavas,Path=ActualHeight}">
                        </Ellipse>
                    </Canvas>
                </Grid>

                <TextBlock Name="txtBlock"
                           Margin="{TemplateBinding Button.Padding}"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Center"
                           Text="{TemplateBinding Button.Content}" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger  Property="Button.IsMouseOver"
                          Value="True">
                    <!--//创建故事板对玻璃罩进行旋转-->
                    <Trigger.EnterActions>
                        <BeginStoryboard x:Name="glassstory">
                            <Storyboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="cubeRotateTransform"
                                                     Storyboard.TargetProperty="Angle"
                                                     By="360"
                                                     Duration="0:0:1"
                                                     RepeatBehavior="Forever" />
                                </Storyboard>
                            </Storyboard>
                        </BeginStoryboard>

                    </Trigger.EnterActions>
                </Trigger>
                <!--<按钮离开暂停动画>-->
                <Trigger Property="Button.IsMouseOver"
                         Value="False">
                    <Trigger.EnterActions>
                        <PauseStoryboard BeginStoryboardName="glassstory"></PauseStoryboard>
                    </Trigger.EnterActions>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Window.Resources>
因为在圆形按钮按下的时候会有虚线框,没办法,就让按钮的属性FocusVisualStyle 为空,也没找到其它好的办法,有懂的给俺留言说下怎么搞,谢谢,代码如下:

   <Style  TargetType="{x:Type Button}">
            <Setter Property="FocusVisualStyle"
                    Value="{x:Null}" />


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值