This is a migrated thread and some comments may be shown as answers.

Load On Demand

2 Answers 59 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 02 Apr 2013, 10:01 PM
Using Q1 2013

I've been trying to get load on demand working with a TreeListView.  I have found many posts here that point to the demo: http://demos.telerik.com/silverlight/#TreeListView/OnDemandDataLoading

I implemented my TreeListView just like the example -- except there is one big difference.  The demo is just loading from an xml file - a synchronous operation.  The more likely scenario in Silverlight is an asynchronous operation.  In my treelistview, I call a web service when IsExpanded is set to true.  When the call comes back I load the child item collection, and call NotifyPropertyChanged for the collection, however the TreeListView does NOT update.  So it appears that this is not a viable option for load on demand unless I'm missing something,

To verify that its not a different issue, I populate the child collection with dummy data (synchronous) when expanded is set to true -- and the treelistview behaves correctly. 
I also have a breakpoint in the return method of the service to verify there were no errors, and the child collection gets loaded with items.

My final attempt was to initialize the child collection when IsExpanded is set to true, and then just populate it when the webservice call returns -- assuming that because the collection is observable, it would update the treelistview.  No luck there either.

Any thoughts?  Have you made any sample projects that accesses web services?
<telerik:RadTreeListView Height="400" AutoExpandItems="False" IsFilteringAllowed="False"
     IsReadOnly="True" ItemsSource="{Binding Path=CurrentTree.ChildItems}"
     IsExpandedBinding="{Binding IsExpanded, Mode=TwoWay}"
     IsExpandableBinding="{Binding IsExpandable}">
       <telerik:RadTreeListView.ChildTableDefinitions>
         <telerik:TreeListViewTableDefinition ItemsSource="{Binding ChildItems}" />
       </telerik:RadTreeListView.ChildTableDefinitions>
</telerik:RadTreeListView>


public class RelationTreeItem : BaseViewModel
{
  private ObservableCollection<RelationTreeItem> _ChildItems;
  public ObservableCollection<RelationTreeItem> ChildItems
  {
    get { return _ChildItems; }
    protected set { _ChildItems = value; }
  }
  private bool _IsExpandable = true;
  public bool IsExpandable
  {
    get { return _IsExpandable; }
    set
    {
      if (_IsExpandable != value)
      {
        _IsExpandable = value;
        NotifyPropertyChanged("IsExpandable");
      }
    }
  }
  private bool _IsExpanded = false;
  public bool IsExpanded
  {
    get { return _IsExpanded; }
    set
    {
      if (_IsExpanded != value)
      {
        _IsExpanded = value;
        if (_IsExpanded)
          LoadChildren();
        NotifyPropertyChanged("IsExpanded");
       }
    }
  }
 
  private void LoadChildren()
  {
    WFServiceClient client = new WFServiceClient();
    client.GetItemsCompleted += delegate(object s, GetItemsCompletedEventArgs e)
    {
      client.CloseAsync();
      this.ChildItems = new ObservableCollection<RelationTreeItem>();
      foreach (var x in e.Result)
        this.ChildItems.Add(new RelationTreeItem(x)));
 
      NotifyChildrenLoaded();
    };
    client.GetNodeRelationshipsAsync(criteria);
  }
 
  protected void NotifyChildrenLoaded()
  {
    NotifyPropertyChanged("ChildItems");
   }
}

2 Answers, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 02 Apr 2013, 10:11 PM
Like always -- as soon as I post I find a solution...

I initialized the child collection in the constructor instead of in the IsExpanded property, and that solved the problem.

Thanks,
Justin
0
Rob Conley
Top achievements
Rank 1
answered on 04 May 2013, 06:14 PM
Jason --

You're saying that you did

this.ChildItems = new ObservableCollection<RelationTreeItem>();

In the RelationTreeItem constructor, correct?
Tags
TreeListView
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Rob Conley
Top achievements
Rank 1
Share this question
or