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

Silverligh treevieew control Load On Demand feature not working

2 Answers 63 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Murtaza Tinwala
Top achievements
Rank 1
Murtaza Tinwala asked on 19 Sep 2009, 10:53 AM
Hi Telerik guys,

Thanks for providing a great control like Silverlight Telerik.

I am highly interested in its Load-on-demand feature but unfortunately it is not working in my application.

Please find the code I am using.

XAML

<telerikCore:HierarchicalDataTemplate x:Key="Emp" ItemsSource="{Binding Subordinates}">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Name}" FontWeight="Bold" FontSize="12" />
                    <TextBlock Text="{Binding Age}" FontWeight="Bold" FontSize="12" />
                </StackPanel>
            </telerikCore:HierarchicalDataTemplate>


<telerikNavigation:RadTreeView Width="290"  HorizontalAlignment="Left" x:Name="tree"
                VerticalAlignment="Top" IsLoadOnDemandEnabled="True"  ItemTemplate="{StaticResource Emp}" 
LoadOnDemand="tree_LoadOnDemand" />

Code snippet

public class Emp
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public ObservableCollection<Emp> Subordinates { get; set; }
    }


void tree_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
            Emp emp = item.Item as Emp;
            if (emp != null)
            {
                emp.Subordinates = new ObservableCollection<Emp>();
                emp.Subordinates.Add(new Emp() { Name = "Runtimeload", Age = 46 });
            }
            else
                item.IsLoadOnDemandEnabled = false;
        }

I checked by debugging.  The LoadOnDemand event does get fired when I click the expander button in treeview.  But still no new child nodes appear.  It just keeps showing the default animation infinitely. 

I downloaded a similar demo application and its load on demand is also not working - however event does get triggered.  I am banging my head against wall for this simple problem.  There is not much of code and I wonder what I am doing wrong.  In your example solution, the load on demand works as expected.

Please respond as early as possible.  Let me know if you need full source code.  This bug/problem has become the blocking feature in my project and we are nearing the release.

Regards,
Murtaza

2 Answers, 1 is accepted

Sort by
0
Accepted
Valentin.Stoychev
Telerik team
answered on 22 Sep 2009, 10:15 AM
Hi Murtaza Tinwala,

The problem in your code was that the RadTreeView was not notified about the changed value of the "Subordinates" property and thus its visual representation was not changed.

To fix this you should change a little bit the implementation of your class:
public class Emp  
    {  
        private ObservableCollection<Emp> subordinates = new ObservableCollection<Emp>();  
        public string Name { getset; }  
        public int Age { getset; }  
        public ObservableCollection<Emp> Subordinates {  
            get 
            {  
                return subordinates;  
            }  
            set 
            {  
                subordinates = value;  
                  
            }  
        }  
 
    } 

And then to modify the load on demand handler:
void tree_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)  
        {  
            RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;  
            Emp emp = item.Item as Emp;  
            if (emp != null)  
            {  
                 //emp.Subordinates = new ObservableCollection<Emp>();  
                emp.Subordinates.Add(new Emp() { Name = "Runtimeload", Age = 46 });  
            }  
            else 
                item.IsLoadOnDemandEnabled = false;  
        } 


Please let us know how it goes.

Sincerely yours,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Murtaza Tinwala
Top achievements
Rank 1
answered on 22 Sep 2009, 11:23 AM
Thanks guys.  This has resolved our problem.
Murtaza
Tags
TreeView
Asked by
Murtaza Tinwala
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Murtaza Tinwala
Top achievements
Rank 1
Share this question
or