Situation
I get the following inconsistent behavior in my application: one of about 20 executions, the WPFToolkit DataGrid tied to a DataTable , will not display all rows without missing anything from 1 to 3 of the total 4 rows that were expected.
Internal work
DataGrid bound to DataTable , D1 , which is a property of the custom class C1 .- When the user stimulates the presentation, we must retrieve the data from the back-end, which may take some time. To do this, we create a stream (in fact, for this we use
BackgroundWorker , but it seems there is no difference that it uses one or the other), which runs the M1 method, which opens the connections and request data. This thread is used to avoid the use of an unresponsive application. - M1 retrieves the data and first saves it on the DTO. After that, he asks C1 to clear the table. C1 does this (by calling a
D1.Clear() ) and raises NotifyPropertyChanged() (from the stream). - M1 passes the new
DataTable backend to C1 , which inserts row by row into D1. After the insert of the C1 rows is NotifyPropertyChanged() , NotifyPropertyChanged() occurs. The thread ends.
So, in other words, I clear the table, notify WPF, insert data, notify WPF, and exit.
In my opinion, while the last Notify is correctly consumed from the user interface, it should always show all the lines.
In addition to the DataTable , there are a large number of properties (mainly strings and int) that are updated and thus notified. We do not observe this behavior in any other case, only with a DataTable .
I know this goes deeper into WPF mechanisms for binding, but I hope someone can shed some light here. Any information on WPF binding or multithreading with WPF is welcome.
source share