WPF动画警告:6:无法执行操作 [英] WPF Animation Warning: 6 : Unable to perform action

查看:56
本文介绍了WPF动画警告:6:无法执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VIsual Studio输出面板中的WPF应用程序中观察到以下警告:

I observe in my WPF application warning in VIsual Studio Output panel with following text:


WPF动画警告:6:无法执行操作,因为指定的
情节提要板从未应用到此对象以进行交互式
控件。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 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'

如何将HashCode反转为某些xaml元件?如何查找该动画的附加位置?

How can I 'reverse' HashCode to some xaml element? How to find where that animation is attached?

预先感谢

推荐答案

您可以使用以下代码找到您的StoryBoard:

You can use the following code to find your 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;
}

执行如下方法:

    string storyBoardName = GetStoryBoardNameByHashCode(65981734);

这应该能够使用HashCode获得StoryBoard-Name(如果您想获得指定的StoryBoard,您也可以将其返回)。请注意,此处的ResourceDictionary位于窗口范围内(本地)。因此,如果StoryBoards都位于应用程序的ResourceDictionary(App.xaml)中,则将 Resources更改为:

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:

Application.Current.Resources

可能有另一种方法来获取WPF应用程序的所有资源而不只是本地或应用程序范围,但尚未对此进行研究。希望这段代码可以让您找到问题所在。

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.

这里是示例代码,以防万一您需要它!

Here's the sample code, just in case you'd need it!

这篇关于WPF动画警告:6:无法执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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