Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I'm writing my first WPF application and I'm trying to implement a fade animation when the form closes. I came across this question Fading out a wpf window on closeFading out a wpf window on close which shows how to make a fade-out animation but I can't seem to get it working. I have this in my XAML:

<Window.Resources> <Storyboard Name="FadeOutStoryboard" x:Key="FadeOutStoryboard" Completed="FadeOutStoryboard_Completed"> <DoubleAnimation Storyboard.TargetProperty="Window.Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" /> </Storyboard> </Window.Resources> 

And I then have this event handler:

 private bool doneFade; private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!doneFade) { e.Cancel = true; Storyboard sb = (Storyboard)this.FindResource("FadeOutStoryboard"); sb.Begin(); } } 

But when the sb.Begin() method is called I get this exception:

System.InvalidOperationException: No target was specified for 'System.Windows.Media.Animation.DoubleAnimation'. 

As stated this is my first attempt at WPF so I'm rather comfused at what I need to do to add the fade-out when the form is closing.

I'm writing my first WPF application and I'm trying to implement a fade animation when the form closes. I came across this question Fading out a wpf window on close which shows how to make a fade-out animation but I can't seem to get it working. I have this in my XAML:

<Window.Resources> <Storyboard Name="FadeOutStoryboard" x:Key="FadeOutStoryboard" Completed="FadeOutStoryboard_Completed"> <DoubleAnimation Storyboard.TargetProperty="Window.Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" /> </Storyboard> </Window.Resources> 

And I then have this event handler:

 private bool doneFade; private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!doneFade) { e.Cancel = true; Storyboard sb = (Storyboard)this.FindResource("FadeOutStoryboard"); sb.Begin(); } } 

But when the sb.Begin() method is called I get this exception:

System.InvalidOperationException: No target was specified for 'System.Windows.Media.Animation.DoubleAnimation'. 

As stated this is my first attempt at WPF so I'm rather comfused at what I need to do to add the fade-out when the form is closing.

I'm writing my first WPF application and I'm trying to implement a fade animation when the form closes. I came across this question Fading out a wpf window on close which shows how to make a fade-out animation but I can't seem to get it working. I have this in my XAML:

<Window.Resources> <Storyboard Name="FadeOutStoryboard" x:Key="FadeOutStoryboard" Completed="FadeOutStoryboard_Completed"> <DoubleAnimation Storyboard.TargetProperty="Window.Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" /> </Storyboard> </Window.Resources> 

And I then have this event handler:

 private bool doneFade; private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!doneFade) { e.Cancel = true; Storyboard sb = (Storyboard)this.FindResource("FadeOutStoryboard"); sb.Begin(); } } 

But when the sb.Begin() method is called I get this exception:

System.InvalidOperationException: No target was specified for 'System.Windows.Media.Animation.DoubleAnimation'. 

As stated this is my first attempt at WPF so I'm rather comfused at what I need to do to add the fade-out when the form is closing.

edited tags
Link
Dave Clemmer
  • 3.8k
  • 12
  • 53
  • 72
Source Link
Aaron Powell
  • 25.1k
  • 18
  • 102
  • 151

WPF Storyboard beginner problem

I'm writing my first WPF application and I'm trying to implement a fade animation when the form closes. I came across this question Fading out a wpf window on close which shows how to make a fade-out animation but I can't seem to get it working. I have this in my XAML:

<Window.Resources> <Storyboard Name="FadeOutStoryboard" x:Key="FadeOutStoryboard" Completed="FadeOutStoryboard_Completed"> <DoubleAnimation Storyboard.TargetProperty="Window.Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" /> </Storyboard> </Window.Resources> 

And I then have this event handler:

 private bool doneFade; private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!doneFade) { e.Cancel = true; Storyboard sb = (Storyboard)this.FindResource("FadeOutStoryboard"); sb.Begin(); } } 

But when the sb.Begin() method is called I get this exception:

System.InvalidOperationException: No target was specified for 'System.Windows.Media.Animation.DoubleAnimation'. 

As stated this is my first attempt at WPF so I'm rather comfused at what I need to do to add the fade-out when the form is closing.