polfosol polfosol - 1 year ago 191
C# Question

WPF - Binding the DataContext of a DataGrid to DataTable

I have a

in my WPF window. I bind its
to a
. When I construct and fill my
, the
updates and works perfectly. Now I want to find some elements in my
and highlight their associated cells in the
. How can I do this using the MVVM pattern? What other property of the
I should bind in order to achieve this?

I have been googling for two hours and so far I got nothing. Any hints would be appreciated.

Answer Source

The main problem was with the binding. One shall not bind the DataContext of a DataGrid to a DataTable. The better way is to bind its ItemsSource to the DataTable. Although the result would appear the same.

Secondly, abiding to the MVVM pattern is sometimes really painful and seems unnecessarily complicated. It seems there is no harm in doing some works programmatically.

And finally, this great answer helped me a lot. I refer the future readers with the same issues to that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download