3
votes

I have a VisualTransition inside of a VisualStateGroup for a Button control. The Storyboard property is bound to a StaticResource Storyboard:

<VisualTransition From="MyLock" To="Unlocked" GeneratedDuration="0:0:2.0" Storyboard="{StaticResource Storyboard_Locked_ToUnlocked}"/>

When I go to the "Unlocked" state using the VisualStateManager, I get the following exception: "System.InvalidOperationException: Specified value of type 'System.Windows.Media.Animation.Storyboard' must have IsFrozen set to false to modify." Nothing in the Storyboard is modifying the Storyboard itself so I'm not sure what this means.

Two strange things. Number one, this did not start happening until migrating from VS 2010 to VS 2012 and installing the .Net 4.5 framework. Second, if I copy all of the code and move it into the Storyboard property itself inside a tag, I do not get the error. So it appears to not be anything in the Storyboard itself, just a problem with using a StaticResource for this.

When researching, the only thing I could find about the error dealt with subscribing to the Completed event of the storyboard, which I am not doing anywhere, unless VisualStateManager is doing this somehow.

Thanks in advance for any help.

Edit: I should also add that I want to use this in two different transitions, and that is why I would prefer it to be a StaticResource so I don't have to copy/paste the xaml. I commented out one of the transitions and still got the error so it's not the fact that I'm sharing it either.

1

1 Answers

7
votes

To anyone else who runs into this issue, I have found a solution.

Simply changing the Storyboard to not be shared allows it to be created for each animation call, which gets rid of this error. Set x:Shared to False on the Storyboard to do this:

 <Storyboard x:Shared="False" x:Key="Storyboard_Locked_ToUnlocked">