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.
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.
}
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With