WPF 动画警告:6:无法执行操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12981771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Animation Warning: 6 : Unable to perform action
提问by Dusan Kocurek
I observe in my WPF application warning in VIsual Studio Output panel with following text:
我在 VIsual Studio 输出面板中的 WPF 应用程序警告中观察到以下文本:
WPF Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='65981734'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Controls.ContentPresenter'; TargetElement.HashCode='49882372'; TargetElement.Type='System.Windows.Controls.ContentPresenter'
WPF 动画警告:6:无法执行操作,因为指定的 Storyboard 从未应用于此对象以进行交互控制。Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='65981734'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Controls.ContentPresenter'; TargetElement.HashCode='49882372'; TargetElement.Type='System.Windows.Controls.ContentPresenter'
How can I 'reverse' HashCode to some xaml element? How to find where that animation is attached?
如何将 HashCode“反转”为某个 xaml 元素?如何找到该动画的附加位置?
Thanks in advance
提前致谢
回答by pdvries
You can use the following code to find your StoryBoard:
您可以使用以下代码来查找您的 StoryBoard:
private string GetStoryBoardNameByHashCode(int hashCode)
{
foreach (DictionaryEntry resource in Resources)
{
if (resource.Value is Storyboard)
{
if (resource.GetHashCode() == hashCode)
return ((Storyboard) resource.Value).Name;
}
}
return String.Empty;
}
Execute the method like so:
像这样执行方法:
string storyBoardName = GetStoryBoardNameByHashCode(65981734);
This should be able to get the StoryBoard-Name with the HashCode (ór if you want to get the specified StoryBoard, you can return that as well). Mind you that the ResourceDictionary is on Window-scope (local) here. So, if the StoryBoards are all located in the ResourceDictionary of the Application (App.xaml) then change 'Resources' to:
这应该能够获得带有 HashCode 的 StoryBoard-Name(或者如果你想获得指定的 StoryBoard,你也可以返回它)。请注意,ResourceDictionary 位于此处的 Window 范围(本地)上。因此,如果 StoryBoards 都位于应用程序 (App.xaml) 的 ResourceDictionary 中,则将“Resources”更改为:
Application.Current.Resources
There may be an alternative way to get all the Resources of a WPF-application instead of just the local or Application-scope, but haven't looked into this. Hopefully, this code allows you to find your problem.
可能有另一种方法来获取 WPF 应用程序的所有资源,而不仅仅是本地或应用程序范围,但尚未对此进行研究。希望此代码可以让您找到问题。
Here's the samplecode, just in case you'd need it!
这是示例代码,以防万一您需要它!
回答by Yang C
Actually, I had run into the same problem as you.
其实我也遇到了和你一样的问题。
I had found that the animation's Begin()method didn't get called before its Stop()method being called. So the Runtime throw a warning that the Stop action couldn't be invoked.
我发现动画的Begin()方法在它的Stop()方法被调用之前没有被调用。因此,运行时会发出警告,指出无法调用停止操作。
回答by LawMan
My issue was I had a trailing space in my EventName.
我的问题是我的 EventName 中有一个尾随空格。
<interactivity:EventTrigger EventName="SelectionChanged ">
changed to
变成
<interactivity:EventTrigger EventName="SelectionChanged">

