Maestro
Maestro

Reputation: 9508

WPF Datagrid: Loading_Completed Event?

I have Datagrid and I do something like:

Me.Cursor = Wait
Datagrid.ItemsSource = GetData()
Me.Cursor = Nothing

The problem is that there is a (relatively) large delay between setting the .ItemsSource and the moment when the rows actually rendered. So my cursor is reset to normal much too early.

Is there some kind of event that is raised when the Datagrid is finished loading/rendering the data? I know there is a _LoadingRow event, but it fires during the data load, not when the loading is completed?

Upvotes: 4

Views: 3343

Answers (2)

Drew Jex
Drew Jex

Reputation: 875

I had the same issue (look here), and I solved it by placing this code after I changed the ItemsSource:

Dispatcher.InvokeAsync(() => { System.Windows.Input.Mouse.OverrideCursor = null; }, 
       DispatcherPriority.ApplicationIdle);

It basically waits for the application to become idle before changing the cursor back to default. Using a FrameworkElement.Loaded event was not enough because it wouldn't get raised when I made changes to the ItemsSource, only when the datagrid was first loaded.

Upvotes: 4

MaRuf
MaRuf

Reputation: 1894

You may take a look at BeginInit() and EndInit() methods

Upvotes: 0

Related Questions