C# WPF:在角度动画之前更改旋转变换中心
我想为我的用户控件旋转一个动画,该动画将在控件获得键盘焦点时触发。动画应围绕其中心旋转 问题是,我为加载的动画在控件的左下角设置了原始中心点。因此,为了纠正这个错误,我把控制中心的中心设置在触发器<代码> IS-聚焦 但是我的C# WPF:在角度动画之前更改旋转变换中心,c#,wpf,animation,eventtrigger,C#,Wpf,Animation,Eventtrigger,我想为我的用户控件旋转一个动画,该动画将在控件获得键盘焦点时触发。动画应围绕其中心旋转 问题是,我为加载的动画在控件的左下角设置了原始中心点。因此,为了纠正这个错误,我把控制中心的中心设置在触发器 IS-聚焦 但是我的GetKeyboardFocus动画保持原始中心 触发器是否在事件触发器之后执行?或者我做错了什么 <UserControl x:Class="testtuile.rectangle" xmlns="http://schemas
GetKeyboardFocus
动画保持原始中心
触发器是否在事件触发器之后执行?或者我做错了什么
<UserControl x:Class="testtuile.rectangle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Height="150" Width="300" Padding="4" Focusable="True" MouseDown="UserControl_MouseDown" IsTabStop="True">
<UserControl.RenderTransform>
<RotateTransform Angle="0" CenterX="0" CenterY="150"></RotateTransform>
</UserControl.RenderTransform>
<UserControl.Style>
<Style>
<Style.Triggers>
<Trigger Property="Control.IsFocused" Value="True">
<Setter Property="Control.BorderBrush" Value="Gold"></Setter>
<Setter Property="Control.BorderThickness" Value="2"></Setter>
<Setter Property="Control.RenderTransform">
<Setter.Value>
<RotateTransform CenterX="150" CenterY="75"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Style>
<UserControl.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="(RenderTransform).(RotateTransform.Angle)"
From="90" To="0" Duration="0:0:0.8"
AutoReverse="False"
/>
<DoubleAnimation
Storyboard.TargetProperty="Opacity"
From="0" Duration="0:0:0.6"
AutoReverse="False"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="GotKeyboardFocus">
<EventTrigger.Actions>
<BeginStoryboard Name="ButtonFocusedAnimation">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="(RenderTransform).(RotateTransform.Angle)"
From="-2" To="2" Duration="0:0:1"
AutoReverse="True" RepeatBehavior="Forever"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="LostKeyboardFocus">
<StopStoryboard BeginStoryboardName="ButtonFocusedAnimation" />
</EventTrigger>
</UserControl.Triggers>
<Grid Background="Aquamarine">
</Grid>
谢谢您的帮助。您不必在动画之前更改它。要围绕设置在用户控件上的中心点旋转,请执行以下操作:
<UserControl RenderTransformOrigin="0.5,0.5" ...>
获取或设置由RenderTransform声明的任何可能的渲染转换的中心点,相对于元素的边界
后来
RenderTransferMorigin对点结构值的使用有点不标准,因为点并不表示坐标系中的绝对位置。相反,0和1之间的值被解释为每个x、y轴中当前元素范围的因子。例如,(0.5,0.5)将导致渲染变换位于元素的中心,或者(1,1)将渲染变换放置在元素的右下角
谢谢dkozl。我不会告诉你细节,但你今晚救了我。因此+1。