WPF故事板需要的TargetName [英] WPF Storyboard requires TargetName

查看:2617
本文介绍了WPF故事板需要的TargetName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有弹出正在播放窗口,在我的应用程序,现在我想申请到它的显示/隐藏任何凉爽的效果。我不想创建/每次我需要显示/隐藏处理窗口,所以我想我不能使用 Window.Triggers 。我创建的样本故事板和code,后面调用它;因此,它立刻陷入异常没有目标是为'System.Windows.Media.Animation.DoubleAnimation 指定。我发现这个答案并添加 Storyboard.TargetName 属性。

I have popup "Now playing" window in my app, and now I want to apply any cool effect to its show/hide. I don't want to create/dispose window each time I need to show/hide it, so I suppose I can't use Window.Triggers. I created sample storyboard and invoke it from code-behind; So it instantly fall into exception No target was specified for 'System.Windows.Media.Animation.DoubleAnimation. I found this answer and added Storyboard.TargetName attribute.

    <Window.Resources>
        <Storyboard x:Key="OpenAnimation">
            <DoubleAnimation Storyboard.TargetName="NowPlaying" Storyboard.TargetProperty="(Window.Opacity)" Duration="0:0:5" From="0" To="1" />
        </Storyboard>
    </Window.Resources>

但它抛出另一个异常:无法找到命名空间名称NowPlayingVKPlaylist.GUI.NowPlaying但窗口code-隐藏类的名称。 IS NowPlaying 。我也试过全名命名空间,并没有改变的东西。

But it throws another exception: Can't find name "NowPlaying" in namespace "VKPlaylist.GUI.NowPlaying". But window code-behind class name IS NowPlaying. I also tried full name with namespace and it didn't change things.

我应该如何在这个属性指向正确的名称?有没有像这个故事板这样会知道哪里办理任何动画神奇的关键字?我不能在XAML name属性分配到窗口(大概不得)。它看起来像在回答上面的纨绔子弟容易解决了他的问题,只是通过增加该属性。我所缺少的?

How should I point proper name in this attribute? Is there any "magic" keyword like "this" so storyboard will know where to apply animation? I can't assign name attribute to window in XAML (and probably must not). It looks like dude in answer above easily solved his issue just by adding this attribute. What I am missing?

推荐答案

您需要设置名称属性在&LT;窗​​口&GT; 的TargetName 可以引用它。

You need to set the Name attribute on your <Window> so that TargetName can reference it.

这篇关于WPF故事板需要的TargetName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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