Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window shown event in WPF?

Tags:

c#

.net

wpf

xaml

I want to apply fade animation every time my window is shown. How to do that from xaml? That window can be hidden and then shown again so I can't use Loaded event.

like image 673
Poma Avatar asked Feb 08 '12 10:02

Poma


2 Answers

You can use the ContentRendered event or override OnContentRendered virtual method like this:

    bool _shown;

    protected override void OnContentRendered(EventArgs e)
    {
        base.OnContentRendered(e);

        if (_shown)
            return;

        _shown = true;

        // Your code here.
    }
like image 75
ezolotko Avatar answered Nov 15 '22 02:11

ezolotko


You could use the

IsVisibleChanged

Event from the WPF Window;

Then in the EventMethod use:

if((bool)e.IsVisible)
{
   // It became visible
}
else
{
  // It became hidden
}

This works with opening a new Window instance, this.Show(), this.hide(), this.Close()

like image 5
MiiChiel Avatar answered Nov 15 '22 01:11

MiiChiel