Анимации в пользовательском контроле - PullRequest
1 голос
/ 07 ноября 2011

У меня есть компонент, с которым я анимирую непрозрачность вперед-назад,

как мне сразу запустить анимацию?

Вот мой ресурс для этой анимации?

<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 Ответ

1 голос
/ 07 ноября 2011

Это может сработать: -

                   <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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...