wpf 中单一样式的不同转换
Different transforms in a single style in wpf
我需要在单一样式的每个 EventTrigger 中进行不同类型的转换,仅对 RenderTransform 使用一个值 属性 效果很好,如下所示:
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1" ScaleY="1"/>
</Setter.Value>
</Setter>
但是当我尝试这样做时:
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Setter.Value>
</Setter>
我什至无法访问 TargetProperty 中的单个 属性,它的完整样式是这样的:
<Style TargetType="k:KinectTileButton" x:Key="BotonTutorial">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="6"/>
<Setter Property="ToolTip" Value="Empuja para seleccionar"/>
<Setter Property="Height" Value="400"/>
<Setter Property="Width" Value="250"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="k:KinectTileButton.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(k:KinectTileButton.RenderTransform).(TranslateTransform.Y)" From="-50" To="0" Duration="0:0:1">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<!--More events-->
<EventTrigger RoutedEvent="k:KinectTileButton.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(k:KinectTileButton.Background).(SolidColorBrush.Color)" To="White" Duration="0:0:0.1" FillBehavior="HoldEnd"/>
<DoubleAnimation Storyboard.TargetProperty="(k:KinectTileButton.RenderTransform).(ScaleTransform.ScaleX)" From="1" To="1.3" Duration="0:0:0.5" FillBehavior="HoldEnd">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="(k:KinectTileButton.RenderTransform).(ScaleTransform.ScaleY)" From="1" To="1.3" Duration="0:0:0.5" FillBehavior="HoldEnd">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<!--End of the style-->
没有 TransformGroup,我只能使用一个值或转换,因此只有一个触发器起作用,我知道在添加按钮时添加这些值更容易,但这将适用于很多按钮.
动画的 TargetProperty 值应该引用 TransformGroup 的 Children
集合,并且不应有像 k:KinectTileButton
:
这样的名称前缀
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].ScaleX" ...>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].ScaleY" ...>
...
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[1].Y" ...>
我需要在单一样式的每个 EventTrigger 中进行不同类型的转换,仅对 RenderTransform 使用一个值 属性 效果很好,如下所示:
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1" ScaleY="1"/>
</Setter.Value>
</Setter>
但是当我尝试这样做时:
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Setter.Value>
</Setter>
我什至无法访问 TargetProperty 中的单个 属性,它的完整样式是这样的:
<Style TargetType="k:KinectTileButton" x:Key="BotonTutorial">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="6"/>
<Setter Property="ToolTip" Value="Empuja para seleccionar"/>
<Setter Property="Height" Value="400"/>
<Setter Property="Width" Value="250"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Style.Triggers>
<EventTrigger RoutedEvent="k:KinectTileButton.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(k:KinectTileButton.RenderTransform).(TranslateTransform.Y)" From="-50" To="0" Duration="0:0:1">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<!--More events-->
<EventTrigger RoutedEvent="k:KinectTileButton.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="(k:KinectTileButton.Background).(SolidColorBrush.Color)" To="White" Duration="0:0:0.1" FillBehavior="HoldEnd"/>
<DoubleAnimation Storyboard.TargetProperty="(k:KinectTileButton.RenderTransform).(ScaleTransform.ScaleX)" From="1" To="1.3" Duration="0:0:0.5" FillBehavior="HoldEnd">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="(k:KinectTileButton.RenderTransform).(ScaleTransform.ScaleY)" From="1" To="1.3" Duration="0:0:0.5" FillBehavior="HoldEnd">
<DoubleAnimation.EasingFunction>
<CubicEase EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<!--End of the style-->
没有 TransformGroup,我只能使用一个值或转换,因此只有一个触发器起作用,我知道在添加按钮时添加这些值更容易,但这将适用于很多按钮.
动画的 TargetProperty 值应该引用 TransformGroup 的 Children
集合,并且不应有像 k:KinectTileButton
:
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].ScaleX" ...>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[0].ScaleY" ...>
...
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.Children[1].Y" ...>