开发者

Change Visual State and use transitions or not based on Dependency Property

I have one control, that I sometimes want to animate a state transition and sometimes I don't.

At the moment I have something like so:

<Grid>
    <Interactivity:Inte开发者_C百科raction.Behaviors>
        <ic:DataStateBehavior Binding="{Binding Direction}" Value="Up" TrueState="Up_Direction" />
    </Interactivity:Interaction.Behaviors>    
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="AnimatedStates">
            <VisualStateGroup.Transitions>
                <VisualTransition x:Name="transition" GeneratedDuration="0:0:1">
                    <VisualTransition.GeneratedEasingFunction>
                        <ElasticEase .../>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
            </VisualStateGroup.Transitions>

            <VisualState x:Name="Up_Direction" >
                <Storyboard>
                    <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" 
                        Storyboard.TargetName="pathArrow" />
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Path x:Name="pathArrow" ...>
        <Path.RenderTransform>
            <RotateTransform Angle="90" />
        </Path.RenderTransform>
    </Path>
</Grid>

This works great, but I want to have a UseTransitions dependency property that controls whether that state transitions are animated or not.

I've tried a few things like setting the GeneratedDuration to 0 on the UseTransitions property changed handler, but it seems to get set after the state has already changed, so has no effect.

I also tried the GoToStateAction with a DataTrigger but they only seem to get triggered on a change and the initial value of the DataContext doesn't set the state correctly.

I've thought about having a ValueConverter on the DataStateBehaviour that evaluates the UseTransition property and triggers different states, but that seems like a really ugly solution.

Anyone have an elegant solution?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜