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

[Solved] LoadOnDemand for a collection based on a DependencyProperty

1 Answer 80 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthew Cartwright
Top achievements
Rank 1
Matthew Cartwright asked on 09 Nov 2009, 04:22 PM

Hi,

My first level collection is an ObservableCollection stored as a DependencyProperty in my usercontrol. This collection has sub-properties that contain the child collections. Using the example in the (offline) help file I have a WCF service being called to load the 2nd level of items OnDemand.

        public ObservableCollection<Batch> Batches  
        {  
            get { return (ObservableCollection<Batch>)GetValue(BatchesProperty); }  
            set { SetValue(BatchesProperty, value); }  
        }  
        public static readonly DependencyProperty BatchesProperty =  
            DependencyProperty.Register("Batches", typeof(ObservableCollection<Batch>), typeof(MyTreeView), new PropertyMetadata(null, BatchesChanged));  
        public static void BatchesChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)  
        {  
            // not doing anything in the callback  
        } 

But, because the treeview is bound to the DependencyProperty, the UI is not getting updated when the sub-collection is added.

Does anyone have an example of this working?

Thanks,
Matt

1 Answer, 1 is accepted

Sort by
0
Matthew Cartwright
Top achievements
Rank 1
answered on 09 Nov 2009, 05:06 PM
This was caused by an problem in the CHM help file. The following XAML is specified for the HierarchicalDataTemplate:

<DataTemplate x:Key="ProductTemplate">  
   <TextBlock Text="{Binding ProductName}" /> 
</DataTemplate> 
<telerik:HierarchicalDataTemplate x:Key="CategoryTemplate" ItemsSource="{Binding Products}" 
 ItemTemplate="{StaticResource ProductTemplate}">  
   <TextBlock Text="{Binding CategoryName}" /> 
</telerik:HierarchicalDataTemplate> 
<HierarchicalDataTemplate x:Key="CategoryTemplate" ItemsSource="{Binding Products}" 
   ItemTemplate="{StaticResource ProductTemplate}">  
   <TextBlock Text="{Binding CategoryName}" /> 
</HierarchicalDataTemplate> 

I had incorrectly taken out the telerik:HierarchicalDataTemplate, instead remove the standard HierarchicalDataTemplate
Tags
TreeView
Asked by
Matthew Cartwright
Top achievements
Rank 1
Answers by
Matthew Cartwright
Top achievements
Rank 1
Share this question
or