本文介绍了WPF:更改角度动画前RotateTransform中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的用户控制做一个简单的旋转动画。当控件获得键盘焦点这部动画被触发。我希望它围绕其中心旋转。

的问题是,我设置原始中心点上所装载的动画控制的左下角。因此,纠正,我设置中心在上IsFocused触发器的控制的中间

但我GetKeyboardFocus动画保持原来的中心。

是的EventTrigger后执行触发器?还是我做错了什么。

 <用户控件X:类=testtuile.rectangle
         的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/$p$psentation
         的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
         的xmlns:MC =htt​​p://schemas.openxmlformats.org/markup-compatibility/2006
         的xmlns:D =htt​​p://schemas.microsoft.com/ex$p$pssion/blend/2008
         MC:可忽略=D
         D:DesignHeight =300D:DesignWidth =300HEIGHT =150WIDTH =300填充=4调焦=真的MouseDown =UserControl_MouseDownIsTabStop =真>
< UserControl.RenderTransform>
    &所述; RotateTransform角度=0的centerX =0CenterY =150>&下; / RotateTransform>
< /UserControl.RenderTransform>
< UserControl.Style>
    <样式和GT;
        < Style.Triggers>
            <触发属性=Control.IsFocusedVALUE =真>
                < setter属性=Control.BorderBrushVALUE =黄金>< /二传手>
                < setter属性=Control.BorderThicknessVALUE =2>< /二传手>
                < setter属性=Control.RenderTransform>
                    < Setter.Value>
                        < RotateTransform的centerX =150CenterY =75/>
                    < /Setter.Value>
                < /二传手>
            < /触发>
        < /Style.Triggers>
    < /样式和GT;
< /UserControl.Style>
< UserControl.Triggers>
    <的EventTrigger RoutedEvent =装>
        < EventTrigger.Actions>
            < BeginStoryboard>
                <情节提要>
                    < D​​oubleAnimation是
                        Storyboard.TargetProperty =(的RenderTransform)。(RotateTransform.Angle)
                        从=90为=0时长=0:0:0.8
                        自动翻转=FALSE
                    />
                    < D​​oubleAnimation是
                        Storyboard.TargetProperty =透明度
                        从=0时长=0:0:0.6
                        自动翻转=FALSE
                    />
                < /故事板>
            < / BeginStoryboard>
        < /EventTrigger.Actions>
    < /&的EventTrigger GT;
    <的EventTrigger RoutedEvent =GotKeyboardFocus>
        < EventTrigger.Actions>
            < BeginStoryboard NAME =ButtonFocusedAnimation>
                <情节提要>                    < D​​oubleAnimation是
                        Storyboard.TargetProperty =(的RenderTransform)。(RotateTransform.Angle)
                        从= - 2要=2持续时间=0:0:1
                        自动翻转=真的repeatBehavior =永远
                    />
                < /故事板>
            < / BeginStoryboard>
        < /EventTrigger.Actions>
    < /&的EventTrigger GT;
    <的EventTrigger RoutedEvent =LostKeyboardFocus>
        < StopStoryboard BeginStoryboardName =ButtonFocusedAnimation/>
    < /&的EventTrigger GT;
< /UserControl.Triggers><网格背景=海蓝宝石>
< /网格和GT;

感谢您的帮助。


解决方案

您不必动画之前去改变它。要旋转轮中心点集<$c$c>UIElement.RenderTransformOrigin用户控件

 &LT;用户控件RenderTransformOrigin =0.5,0.5...&GT;

and later

这篇关于WPF:更改角度动画前RotateTransform中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 00:49