用户控件中的动画
本文关键字:动画 控件 用户 | 更新日期: 2023-09-27 18:13:46
我有一个组件,我正在对前后的不透明度进行动画,
如何直接运行动画?
这是我的动画资源?
<RadioButton.Resources>
<Style x:Key="PhoneRadioButtonCheckBoxBase" TargetType="ToggleButton">
<Setter Property="Background" Value="{StaticResource PhoneRadioCheckBoxBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneRadioCheckBoxBrush}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
</Style>
<Style x:Key="RectToggleButton" TargetType="RadioButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid x:Name="grid" Background="Transparent" Loaded="grid_Loaded">
<Grid.Resources>
<Storyboard x:Name="Strobing" AutoReverse="True" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighlightedSprite">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.495"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Grid.Resources>
这可能行得通:-
<Grid x:Name="grid" Background="Transparent" >
<Grid.Triggers>
<EventTrigger RoutedEvent="RadioButton.Loaded">
<BeginStoryboard>
<Storyboard AutoReverse="True" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighlightedSprite">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.495"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
或者你可以试试这个:-
<ControlTemplate TargetType="RadioButton">
<Grid x:Name="grid" Background="Transparent">
<VisualStateManger.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard AutoReverse="True" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighlightedSprite">
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.495"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManger.VisualStateGroups>