TreeView Children Loading Indicator
-
I've got a WPF TreeView that is using the structure in Josh Smith's article[^] In my case I've only got one type of object (Unit) that has a self-referencing hierarchy. So I only have one item ViewModel and so only the one HierarchicalDataTemplate. Everything 'works', but there are two usability issues: 1) clicking on the expander can take a while, and there's nothing to indicate to the user that its happening. 2) the expanders appear on items that have no children (I assume due to the DummyChild that gets added. For the 1st issue, I added a INPC property
IsLoading
to the base item VMTreeViewItemViewModel
. Then I've been round and round in circles trying to get this working...at the moment I've got... In my UnitTreeItemViewModel in theLoadChildren
override I setIsLoading
before and after.IsLoading = true;
//sim a delay
Thread.Sleep(TimeSpan.FromSeconds(0.75).Milliseconds);UI.UIDispatcher.Invoke((ThreadStart)delegate()
{
foreach (Unit u in UnitCache.Units.AllUnits.Where(WhereClause))
base.Children.Add(new UnitTreeItemViewModel(u, this, _uh));
});IsLoading = false;
Finally I added a simple
TextBlock
that I make visible based onIsLoading
:But all this does is show on the child items (after they appear), not the parent:( I've tried changing it to set the Parent's IsLoading, but that didn't seem to work either, the root items don't have Parents for a start... And now I'm stuck... I've created a Pastie of the full code here.
-
I've got a WPF TreeView that is using the structure in Josh Smith's article[^] In my case I've only got one type of object (Unit) that has a self-referencing hierarchy. So I only have one item ViewModel and so only the one HierarchicalDataTemplate. Everything 'works', but there are two usability issues: 1) clicking on the expander can take a while, and there's nothing to indicate to the user that its happening. 2) the expanders appear on items that have no children (I assume due to the DummyChild that gets added. For the 1st issue, I added a INPC property
IsLoading
to the base item VMTreeViewItemViewModel
. Then I've been round and round in circles trying to get this working...at the moment I've got... In my UnitTreeItemViewModel in theLoadChildren
override I setIsLoading
before and after.IsLoading = true;
//sim a delay
Thread.Sleep(TimeSpan.FromSeconds(0.75).Milliseconds);UI.UIDispatcher.Invoke((ThreadStart)delegate()
{
foreach (Unit u in UnitCache.Units.AllUnits.Where(WhereClause))
base.Children.Add(new UnitTreeItemViewModel(u, this, _uh));
});IsLoading = false;
Finally I added a simple
TextBlock
that I make visible based onIsLoading
:But all this does is show on the child items (after they appear), not the parent:( I've tried changing it to set the Parent's IsLoading, but that didn't seem to work either, the root items don't have Parents for a start... And now I'm stuck... I've created a Pastie of the full code here.