VisualStateManager - Property setters?

Jan 7, 2009 at 9:04 PM
I am curious if it would be possible for the VisualStateManager to not use animations in the case where the transition time is set to 0 seconds.  This seems like a lot of overhead for something that does not need an animation.  Would it be possible for a VisualState to include a property setter instead of a Storyboard?  I know it is not currently supported but this seems like it would be a good thing to be able to do.  Please let me know what you think of this.

Brent Schooley
Jan 8, 2009 at 1:32 AM
Hi Brent,

I think you make a really good point.  Accordingly, the GoToState method in VisualStateManager takes a parameter "useTransition" to determine whether transition animations should be applied during the specified state change.  If you pass it a false value, then the state change behaves the way you described it.  The target snaps directly to the new visual state, very much like how a property setter would behave.

Hope that helps you Brent.

Saied Khanahmadi
Jan 8, 2009 at 2:53 PM

Thank you for your quick response. 

It is definitely good to hear that the "useTransition" parameter exists.  However, take for example a Button.  Even though the behaviors for MouseOver and Pressed are not built in, the VSM will do what I have seen described as "event interception magic" to make these states work without the need to use the GoToState method.  Since I never use the GoToState method in this case, I would not be able to set that parameter.

The other reason I asked the question about the property setter case (instead of everything being an animation) is that a Storyboard and corresponding Animation is a very intimidating piece of XAML to work with in the case where a developer wants to make a tweak to one of these "instant" states.  This is not a concern for me personally as an integrator (since I am fluent in Blend I would just make the change in Blend), but for developers who do not have an integrator in the mix I suppose a property setter looks more natural to them.

I guess I'm just wondering if the team has given any consideration to making the animations more implicit in the cases where the state change only involves property changes (over 0 time or over non-zero time).  The VisualState could resemble:

<vsm:VisualState x:Name="MouseOver" Duration="0.2">
    <Setter Property="Opacity" TargetName="bd" Value="50"/>

The VSM could then behind the scenes create the Animation over the 0.2 second duration as an implicit animation.  In cases where the timeline is used to build out keyframe based animations, the current model of using an explicit Storyboard could be used.  Any thoughts?

Jan 15, 2009 at 12:58 AM

Hi Brent,

These are very good questions.  At this time VSM does not allow for external manipulation of the UseTransitions flag on the GoToState call.  However, there are specific cases in which we ensure that transitions aren't used, such as applying a new template to a control.  The 0 second duration is however not a part of this criteria.  VSM is a huge feature and is still a working progress.  We're prioritizing limitations such as this one and aiming to tend to them in a future release.

As for your next question, in place of a property setter you may want to use a Discrete Animation type, which is fundamentally a property setter accompanied by a timer.  Ultimately, this serves the same purpose as you mentioned above, and both are parallel solutions.  However, the GeneratedDuration property is not effective in this case.  Your options are either using Discrete Animations for better readability and simplicity of your XAML code; regular Animations for access to extra features such as GeneratedDuration; or you may simply use triggers if the overhead cost of Animations is too much for your project.  Please note that the triggers option is not a VSM solution.  The example you provided above might look something like the following using Discrete Animations,

<vsm:VisualState x:Name="MouseOver">
      <DoubleAnimationUsingKeyFrames Storyboard.TargetName="bd"
         <DiscreteDoubleKeyFrame KeyTime="00:00:00.2" Value="0.5"/>

Saied Khanahmadi