I'm trying to add a fade effect (animation) for WPF UserControls
(although rather for FrameworkElement
, to make it more general).
If I let the Loaded
event trigger the initial fade-in, the fade animation will sometimes have started before the UserControl has been displayed. The result is a mess. That happens for example if the UserControl does something lengthy (a few tenths of a second), like execute a query, in the Loaded event handler.
So, I would need to handle some event that FrameworkElement/UserControl gets when the content has been rendered, and start the fade-in then. The System.Windows.Window
has a ContentRendered
event, but UserControl has not. So, what event is fired when a FrameworkElement (or UserControl) has been rendered?
Try to check size on SizeChanged or LayoutUpdated. Do job when actual width or height not equals to 0.
view.LayoutUpdated+=(o,e)=> { if (!loaded && (view.ActualHeight > 0 || view.ActualWidth > 0)) { // You can also unsubscribe event here. loaded =true; } }
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