I have a WPF DataGrid to whose ItemsSource is bound to an ObservableCollection>.
Tuple is a simple class I made that stores 4 strings in an array. Here is a generic version:
public class Tuple<T>: INotifyPropertyChanged
{
private int _size = 0;
public Tuple(int size)
{
this._size = size;
_objs = new T[_size];
}
private T[] _objs;
public T this[int i]
{
get
{
return _objs[i];
}
set
{
_objs[i] = value;
OnPropertyChanged(".[" + i + "]");
}
}
public void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
At compile time I know I will have 4 columns and so I bind them to an index of the Tuple. At runtime, Tuples are added to the ObservableCollection and also modified. However, I am running into a problem where my DataGrid only updates when the Tuple is created... That is I get output that looks like this:
The data is present in the ObservableCollection, as if you scroll the DataGrid in and out of view, the text inside the cells appears:
Any tips?