Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is WPF DataGrid DataBindingComplete event?

I need to take some action (e.g. make some cells readonly based on some other cells) after data biinding is completed. In WinForm DataGridView, I used to do it in DataBindingComplete event. However, I couldn't find such an event in WPF DataGrid. What else can I use?

like image 565
newman Avatar asked Oct 01 '10 02:10

newman


3 Answers

This is what I figured out: DataContextChanged event is the right event to use. The only problem is that the datagrid is not quite ready to be consumed in my code inside this event. However, it works fine if I use Dispatcher.BeginInvoke like this:

Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => DoSomethingWithGrid()));

Can anybody explain why this is necessary?

Actually, when dealing with WPF DataGrid, I had to use Dispatcher in quite a few cases in order to make it work. Why?

like image 87
newman Avatar answered Sep 19 '22 18:09

newman


DataContextChanged.

like image 26
Chris Holmes Avatar answered Sep 18 '22 18:09

Chris Holmes


May be you are using threads and datagrid is not thread-safe as all UI components.

like image 44
Muhammad Alaa Avatar answered Sep 17 '22 18:09

Muhammad Alaa