WPF - SelectionChanged上的动画

时间:2010-10-29 08:16:57

标签: wpf animation selectionchanged

如何将选项颜色从未选中的颜色更改为选定的颜色,并在SelectionChanged上添加动画,以便未选择和选定的TabItem都会更改?

编辑:这就是我的CustomTemplate的样子。根本没有动画发生,所以我做错了什么?

 <Style TargetType="TabItem">
        <Setter Property="IsEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TabItem">
                    <Grid>
                        <Border BorderBrush="Transparent" BorderThickness="0" MinWidth="120">
                            <StackPanel Orientation="Vertical">
                                <ContentPresenter HorizontalAlignment="Center" ContentSource="Header" />
                                <Ellipse Name="Ellipse" Stroke="Black" StrokeThickness="1" Width="24" Height="24" Margin="5" Fill="Transparent" />
                            </StackPanel>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True" />
                                <Condition Property="Ellipse.Fill" Value="Transparent" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="Ellipse" Storyboard.TargetProperty="Fill"
                                                        From="Transparent" To="Orange" Duration="0:0:1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="False" />
                                <Condition Property="Ellipse.Fill" Value="Orange" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="Ellipse" Storyboard.TargetProperty="Fill"
                                                        From="Orange" To="Transparent" Duration="0:0:1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

1 个答案:

答案 0 :(得分:0)

您可以定义自定义TabItem模板并使用触发器运行动画。