按钮模板,标题抖动

                <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>中定义路由事件控制,定义故事板,触发

posted @ 2016-04-06 17:26  昨天梦想  阅读(250)  评论(0编辑  收藏  举报