有没有一种方法可以在XAML中为样式模板化,以在一组分组的椭圆中为颜色设置动画?

时间:2019-05-08 14:46:24

标签: wpf-controls

WPF中是否有一种方法可以为StackPanel创建模板样式,从而以1秒的速率对一组椭圆控件中的一组颜色进行动画处理,并且最重要的是由StackPanel的整体组可见性触发?

我无法在“可见性”属性的“模板样式”中创建触发器。这是我尝试过的一种样式,该样式将应用于包含三个Ellipse控件的Stackpanel:

<UserControl.Resources>

    <Color x:Key="C_387DD4" R="56" G="125" B="212"  />
    <Color x:Key="C_D3D3D3" R="211" G="211" B="211"  />

    <Style TargetType="FrameworkElement" x:Key="AnimateOnVisibility">
        <Setter Property="Visibility" Value="Collapsed"/>
        <Style.Triggers>
            <Trigger Property="Visibility" Value="Visible">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                                    Storyboard.TargetName="EL01" 
                                                    Duration="0:0:4"
                                                    FillBehavior="HoldEnd"
                                                    RepeatBehavior="Forever">
                                <ColorAnimationUsingKeyFrames.KeyFrames>
                                    <DiscreteColorKeyFrame KeyTime="0:0:0" Value="{StaticResource C_D3D3D3}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:1" Value="{StaticResource C_387DD4}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:2" Value="{StaticResource C_387DD4}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:3" Value="{StaticResource C_387DD4}"/>
                                </ColorAnimationUsingKeyFrames.KeyFrames>
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                                    Storyboard.TargetName="EL02" 
                                                    Duration="0:0:4"
                                                    FillBehavior="HoldEnd"
                                                    RepeatBehavior="Forever">
                                <ColorAnimationUsingKeyFrames.KeyFrames>
                                    <DiscreteColorKeyFrame KeyTime="0:0:0" Value="{StaticResource C_D3D3D3}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:1" Value="{StaticResource C_D3D3D3}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:2" Value="{StaticResource C_387DD4}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:3" Value="{StaticResource C_387DD4}"/>
                                </ColorAnimationUsingKeyFrames.KeyFrames>
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                                    Storyboard.TargetName="EL03" 
                                                    Duration="0:0:4"
                                                    FillBehavior="HoldEnd"
                                                    RepeatBehavior="Forever">
                                <ColorAnimationUsingKeyFrames.KeyFrames>
                                    <DiscreteColorKeyFrame KeyTime="0:0:0" Value="{StaticResource C_D3D3D3}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:1" Value="{StaticResource C_D3D3D3}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:2" Value="{StaticResource C_D3D3D3}"/>
                                    <DiscreteColorKeyFrame KeyTime="0:0:3" Value="{StaticResource C_387DD4}"/>
                                </ColorAnimationUsingKeyFrames.KeyFrames>
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
            </Trigger>
        </Style.Triggers>
    </Style>

</UserControl.Resources>

我最终需要一个椭圆的水平系列,当StackPanel的“可见性”属性变为“可见”时,则椭圆中颜色的动画从左到右-这是为了给用户一种“请稍候”的感觉,该软件会做一些后台工作。

0 个答案:

没有答案