在Dragenter上对tabItem进行动画处理

时间:2018-10-12 13:58:40

标签: wpf xaml animation

当我在一个选项卡上拖动时试图在我的tabcontrol中创建一个效果,我想将它向右移动x个像素,从而在我拖动时创建滑动效果,但是我似乎无法使动画触发。我在这里想念什么:

                       <Style TargetType="{x:Type TabItem}">                               
                            <Setter Property="RenderTransform">
                                <Setter.Value>
                                    <TransformGroup>
                                        <RotateTransform />
                                        <TranslateTransform />
                                        <SkewTransform />
                                        <ScaleTransform />
                                    </TransformGroup>
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type TabItem}">
                                    <ControlTemplate.Triggers>
                                        <EventTrigger RoutedEvent="TabItem.DragEnter" >
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation 
                                                         Storyboard.TargetProperty="(TabItem.RenderTransform).(TranslateTransform.X)"
                                                         From="0"
                                                         To="50"
                                                         Duration="0:0:0.5"
                                                         FillBehavior="Stop"/>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>

1 个答案:

答案 0 :(得分:0)

您已将RenderTransform属性设置为TransformGroup,并且要对此第二个孩子的X属性进行动画处理,因此应将Storyboard.TargetProperty设置为RenderTransform.Children[1].X

<DoubleAnimation 
    Storyboard.TargetProperty="RenderTransform.Children[1].X"
    From="0"
    To="50"
    Duration="0:0:0.5"
    FillBehavior="Stop"/>

如果您将DoubleAnimation属性设置为RenderTransform,则当前的TranslateTransform应该可以工作:

<Setter Property="RenderTransform">
    <Setter.Value>
        <TranslateTransform />
    </Setter.Value>
</Setter>