wpf - Why does my DataGrid populate only after scrolling in and out of view? -
i have wpf datagrid itemssource bound observablecollection>.
tuple simple class made stores 4 strings in array. here 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] { { return _objs[i]; } set { _objs[i] = value; onpropertychanged(".[" + + "]"); } } public void onpropertychanged(string name) { propertychangedeventhandler handler = propertychanged; if (handler != null) { handler(this, new propertychangedeventargs(name)); } } public event propertychangedeventhandler propertychanged; }
at compile time know have 4 columns , bind them index of tuple. @ runtime, tuples added observablecollection , modified. however, running problem datagrid updates when tuple created... output looks this:
the data present in observablecollection, if scroll datagrid in , out of view, text inside cells appears:
any tips?
your tuple
updates when it's created don't notify index changed whole indexer property has changed:
public t this[int i] { { return _objs[i]; } set { _objs[i] = value; onpropertychanged(binding.indexername); } }
as second part text appears when comes view it's due virtualizingstackpanel
default true
, means items not in view not rendered , bindings not evaluated until in view again
Comments
Post a Comment