Error using StaticResource as Storyboard for a VisualTransition

随声附和 提交于 2020-01-05 03:31:15

问题


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:


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">


来源:https://stackoverflow.com/questions/17622513/error-using-staticresource-as-storyboard-for-a-visualtransition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!