将StaticResource用作VisualTransition的情节提要板时出错 [英] Error using StaticResource as Storyboard for a VisualTransition

查看:215
本文介绍了将StaticResource用作VisualTransition的情节提要板时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VisualStateGroup内部有一个VisualTransition,用于Button控件.故事板属性绑定到StaticResource故事板:

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

当我使用VisualStateManager进入未锁定"状态时,出现以下异常: "System.InvalidOperationException:类型'System.Windows.Media.Animation.Storyboard'的指定值必须将IsFrozen设置为false才能进行修改." 情节提要中没有任何内容可以修改情节提要本身,因此我不确定这意味着什么.

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.

两个奇怪的事情.第一,直到从VS 2010迁移到VS 2012并安装.Net 4.5框架后,这种情况才开始发生.其次,如果我复制所有代码并将其移到标签内的Storyboard属性本身中,则不会得到该错误.因此,它似乎不是情节提要板中的任何内容,而仅仅是为此使用StaticResource的问题.

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.

在研究时,我唯一发现的错误就是订阅情节提要的Completed事件,除非VisualStateManager以某种方式进行此操作,否则我不会在任何地方做这件事.

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.

在此先感谢您的帮助.

我还应该补充一点,我想在两个不同的过渡中使用它,这就是为什么我更希望它是一个StaticResource,所以我不必复制/粘贴xaml.我注释了其中一个转换,但仍然出现错误,因此也不是我也要共享它.

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.

推荐答案

对于遇到此问题的其他人,我已经找到了解决方案.

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

只需将情节提要板更改为不共享,即可为每个动画调用创建情节提要板,从而避免了此错误.在情节提要板上将x:Shared设置为False即可:

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

这篇关于将StaticResource用作VisualTransition的情节提要板时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆