The
DataTable
class pre-dates WPF and was designed for WinForms applications. WPF & WinForms use two very different Binding systems.
To demonstrate this, if you bind a
List
class to a WPF
ItemsContainer
control like <codeDataGrid, any changes to the collection will not be reflected. This is due to the <code>INotifyCollectionChanged and
INotifyPropertyChanged
not being implemented. You can see this when you look at the
DataTable[
^] class:
[SerializableAttribute]
public class DataTable : MarshalByValueComponent, IListSource,
ISupportInitializeNotification, ISupportInitialize, ISerializable,
IXmlSerializable
WPF has a special collection class called
ObservableCollection<T>
. Looking at
ObservableCollection<t>[
^] class you can see the two interfaces for binding are implemented:
[SerializableAttribute]
public class ObservableCollection<T> : Collection<T>, INotifyCollectionChanged,
INotifyPropertyChanged
You might be able to exten the
DataTable
class to capture key events and reflect the row changes, however each cell will also require the
INotifyPropertyChanged
interface implemented as well. It would be far simplier to modify your code to work with the
ObservableCollection<T>
and data model classes (with
INotifyPropertyChanged
implemented).
If you want to learn more about how the WPF binding system works, Pete O'Hanlon has a great multipart series that he is doing at the moment:
Bare Metal MVVM - Where The Code Meets The Road - Part 1[
^]