码迷,mamicode.com
首页 > 其他好文 > 详细

按钮模板,标题抖动

时间:2016-04-06 18:16:50      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="btn_border" Background="{TemplateBinding Background}" >

                        <TextBlock x:Name="btn_text" Opacity="0" RenderTransformOrigin="0.5,0.5" Text="{TemplateBinding Content}" FontSize="18" FontFamily="Candara" Foreground="Red" FontWeight="Normal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0 5 0 0" >
                             <TextBlock.RenderTransform>
                                <RotateTransform></RotateTransform>
                            </TextBlock.RenderTransform>
                        </TextBlock>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Cursor" Value="Hand" TargetName="btn_border" />
                            <Setter Property="Opacity" Value="1"  TargetName="btn_text">

                            </Setter>
                        </Trigger>
                        <EventTrigger  RoutedEvent="Button.MouseEnter">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard >
                                        <DoubleAnimation  Storyboard.TargetName="btn_text"
                                                     Storyboard.TargetProperty="RenderTransform.Angle"  
                                                     BeginTime="00:00:00" From="0" To="5" Duration="00:00:0.1" 
                                                     AutoReverse="True"   RepeatBehavior="Forever"  />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="Button.MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="btn_text" Storyboard.TargetProperty="RenderTransform.Angle"
                                                   BeginTime="00:00:00" From="0" To="0" Duration="00:00:0.1" AutoReverse="True"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>

关键在与在需要变换的元素内声明 元素中心 RenderTransformOrigin(0.5,0.5)

<XX.RenderTransform>

<RotateTransform></RotateTransform>

</XX.RenderTransform>

然后在<Template.Tragers>中定义路由事件控制,定义故事板,触发

按钮模板,标题抖动

标签:

原文地址:http://www.cnblogs.com/qwhh/p/5360227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!