C# 如何设置自定义组件旋转变换的动画?
鉴于以下情况:C# 如何设置自定义组件旋转变换的动画?,c#,wpf,xaml,storyboard,transformation,C#,Wpf,Xaml,Storyboard,Transformation,鉴于以下情况: <Viewbox> <Foo:Bar x:FieldModifier="private" x:Name="fooBar" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"> <Foo:Bar.RenderTransform&
<Viewbox>
<Foo:Bar
x:FieldModifier="private"
x:Name="fooBar"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RenderTransformOrigin="0.5,0.5">
<Foo:Bar.RenderTransform>
<TransformGroup>
<ScaleTransform
x:FieldModifier="private"
x:Name="xfScale"/>
<RotateTransform
x:FieldModifier="private"
x:Name="xfRotate"/>
</TransformGroup>
</Foo:Bar.RenderTransform>
<Foo:Bar.Style>
<Style TargetType="{x:Type Foo:Bar}">
<Style.Triggers>
<DataTrigger
Binding="{
Binding Flip,
RelativeSource={
RelativeSource AncestorType={
x:Type local:myFooBar}}}"
Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty=""/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Foo:Bar.Style>
</Foo:Bar>
</Viewbox>
对于一个新组件来说,它基本上是一个粘贴在ViewBox内部的奇特标签(用于自动缩放标签),我需要将
故事板.TargetProperty
指向什么才能设置动画,比如,RotateTransform
Angle
属性?您的TargetName
需要分别为您的xfScale/xfRotate命名变换设置
您的TargetProperty将是所用变换的属性
喜欢规模
Storyboard.TargetProperty=“(UIElement.RenderTransform)。(TransformGroup.Children)[0]。(ScaleTransform.ScaleX)”
及
Storyboard.TargetProperty=“(UIElement.RenderTransform)。(TransformGroup.Children)[0](ScaleTransform.ScaleY)”
除了只指定属性外,您还需要提供一个值来设置动画。所以从整体上来说,它会变成这样
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="xfScale"
Storyboard.TargetProperty="X">
<SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0" />
</DoubleAnimationUsingKeyFrames>
对于旋转,您需要角度属性。值得一提的是,Blend使这件事比手工做得更快/更容易,尤其是对于复杂的动画
希望这有帮助,干杯。在尝试您的建议时,我在编译时收到以下异常:错误TargetName属性不能在样式设置器上设置。
另外-我将尝试混合使用;谢谢你的提示。哦,是的,你可以期待。在本例中,您不需要样式,将DataTrigger直接作为交互作用应用于Foo:Bar
,而不是作为样式.Trigger,或者因为它是WPF,所以您应该能够只执行Foo:Bar.Trigger有限混合是一种方法。谢谢你的提示;巨大的帮助。