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

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

问题描述

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

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

WPF 动画警告:6:无法执行操作,因为指定的 Storyboard 从未应用于此对象以进行交互control.Action='停止';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 位于此处的 Window 范围(本地)上.因此,如果 StoryBoards 都位于应用程序 (App.xaml) 的 ResourceDictionary 中,则将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.

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

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