WPF Storyboard requires TargetName

淺唱寂寞╮ 提交于 2019-12-25 02:12:32

问题


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>

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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/16885443/wpf-storyboard-requires-targetname

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!