用户控件中的动画

时间:2011-11-07 12:17:36

标签: c# silverlight windows-phone-7

我有一个组件,我正在制作来回不透明的动画,

如何立即运行动画?

这是我动画的资源吗?

<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>

1 个答案:

答案 0 :(得分:1)

这可能有用: -

                   <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>