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

RadTreeViewItem's does not refresh if underlying twoway bound DataContext is updated

1 Answer 118 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Shifatullah
Top achievements
Rank 1
Shifatullah asked on 03 Feb 2009, 11:04 AM
Hi,

I have bound RadTreeViewItem.ItemsSource to a HierarchicalDataTemplate in TwoWay mode. Now when my underlying DataContext object is changed the associated RadTreeViewItem's properties are also updated but this change does not appear on the screen.

Extracts From XAML Code:
    xmlns:my="clr-namespace:MySilverlightUI"


    <UserControl.Resources>
        <my:MyTreeViewItemCollection x:Key="mobjMyTreeViewItemCollection" />
        <telerik:HierarchicalDataTemplate  x:Key="tplMyTreeViewItem" ItemsSource="{Binding Path=Items, Mode=TwoWay}">
            <TextBlock Height="14" Text="{Binding Path=Header, Mode=TwoWay}" FontSize="10" ></TextBlock>
        </telerik:HierarchicalDataTemplate>
    </UserControl.Resources>

<telerikNavigation:RadTreeView ......
...... ItemsSource="{Binding Source={StaticResource mobjMyTreeViewItemCollection}} />

Extracts From Code Behind:

    public class MyTreeViewItemCollection : ObservableCollection<MyTreeViewItem>
    {    }

    public class MyTreeViewItem
    {
        public string Header;
    }

Now when I update underlying DataContext object like this:

MyTreeViewItem objDataContext = trnNode.DataContext as MyTreeViewItem;
objDataContext.Header = rsNewHeader;

then it shows that underlying Header is changed but this effect is not shown on screen.

If I update the node's header my self like:

trnNode.Header = rsNewHeader;

then on screen node contents are removed and it shows as blank node;

Please do help, I am unable to find out why it is happening? It should update the screen when underlying header property is changed.

Thanks,
Shifatullah


1 Answer, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 03 Feb 2009, 04:03 PM
Hi Shifatullah,

In your case you should make the items in the source collection implement the INotifyPropertyChanged property so that the treeview knows when an item property is changed. Here's a sample item class you can use for your collection (just illustrating how to implement INotifyPropertyChanged ):

public class Book : INotifyPropertyChanged
    {    
        private string bookTitle;    
        public event PropertyChangedEventHandler PropertyChanged;    
        public string Title    
        {        
            get { return bookTitle; }        
            set        
            {            
                bookTitle = value;           
                if ( PropertyChanged != null )            
                {                
                    PropertyChanged(this, new PropertyChangedEventArgs("Title"));            
                }        
            }           
        }       
    }

Let me know if this helps.

All the best,
Tihomir Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Shifatullah
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Share this question
or