C# – Window shown event in WPF

.netc++wpfxaml

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.

Best Solution

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.
    }