Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WPF, is there a "render complete" event?

Tags:

wpf

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 !

like image 242
captainst Avatar asked Nov 30 '22 21:11

captainst


2 Answers

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
    }
like image 104
Ben Walton Avatar answered Dec 19 '22 22:12

Ben Walton


Yes, use the Window.ContentRendered event.

like image 22
James Harcourt Avatar answered Dec 20 '22 00:12

James Harcourt