In WPF, When I load a wrap panel with a lot of elements, the window stalls for a while before showing the content. I would like to add a wait hint but I could not find a way to detect when the wrap panel completes rendering.
I have tried "loaded", "sizechanged", "initialized" without success. Has anyone got any idea on this issue ?
Many thanks !
At the start of rendering call Dispatcher.BeginInvoke
with the Dispatcher Priority of ContextIdle
.
My start of rendering just happened to be a treeview selected item change event, but this could be any event that you need to wait for the UI to finish updating.
private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
Dispatcher.BeginInvoke(new Action(() => DoSomething()), DispatcherPriority.ContextIdle, null);
}
private void DoSomething()
{
//This will get called after the UI is complete rendering
}
Yes, use the Window.ContentRendered event.
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