This question is locked. New answers and comments are not allowed.
I am trying to edit an item in a RadTree using the built in editor. After I edit the item, the underlying collection appears to be updated but the item dissappears from the tree.
Here is a code sample that attempts to follow the pattern illustrated here:
http://www.telerik.com/community/forums/silverlight/treeview/iseditable-and-databinding.aspx
I have created a simple 2-column grid with a RadTree on the left and an ItemsControl on the right. The ItemsControl is simply used to illustrate that the collection has indeed changed.
Here is a code sample that attempts to follow the pattern illustrated here:
http://www.telerik.com/community/forums/silverlight/treeview/iseditable-and-databinding.aspx
I have created a simple 2-column grid with a RadTree on the left and an ItemsControl on the right. The ItemsControl is simply used to illustrate that the collection has indeed changed.
| using System.Collections.ObjectModel; | |
| using System.ComponentModel; | |
| using System.Windows; | |
| using System.Windows.Controls; | |
| using Telerik.Windows.Controls; | |
| namespace Telerik_Quick_Test | |
| { | |
| public partial class Page : UserControl | |
| { | |
| ObservableCollection<ProjectPortfolioType> _data = null; | |
| public ObservableCollection<ProjectPortfolioType> data | |
| { | |
| get | |
| { | |
| if (_data == null) | |
| { | |
| ProjectPortfolioType t = new ProjectPortfolioType() { ID = 1, Name = "root" }; | |
| ProjectPortfolio i = new ProjectPortfolio(t) { Name2 = "node 1" }; | |
| ObservableCollection<ProjectPortfolio> ci = new ObservableCollection<ProjectPortfolio>(); | |
| ci.Add(i); | |
| i = new ProjectPortfolio(t) { Name2 = "node 2" }; | |
| ci.Add(i); | |
| t.ProjectPortfolio = ci; | |
| _data = new ObservableCollection<ProjectPortfolioType>(); | |
| _data.Add(t); | |
| } | |
| return _data; | |
| } | |
| } | |
| public Page() | |
| { | |
| InitializeComponent(); | |
| PortfolioTree.ItemsSource = data; | |
| itemsControl1.ItemsSource = data[0].ProjectPortfolio; | |
| if (PortfolioTree != null) | |
| { | |
| PortfolioTree.Edited += new RadTreeViewItemEditedEventHandler(PortfolioTree_Edited); | |
| } | |
| } | |
| void PortfolioTree_Edited(object sender, RadTreeViewItemEditedEventArgs e) | |
| { | |
| var treeViewItem = e.OriginalSource as RadTreeViewItem; | |
| ProjectPortfolio level1 = (treeViewItem.DataContext) as ProjectPortfolio; | |
| if (level1 != null) | |
| level1.Name2 = e.NewText; | |
| ProjectPortfolioType level2 = (treeViewItem.DataContext) as ProjectPortfolioType; | |
| if (level2 != null) | |
| level2.Name = e.NewText; | |
| } | |
| } | |
| public class ProjectPortfolioType : INotifyPropertyChanged | |
| { | |
| public int ID { get; set; } | |
| public string NameField; | |
| public string Name | |
| { | |
| get | |
| { | |
| return this.NameField; | |
| } | |
| set | |
| { | |
| if ((object.ReferenceEquals(this.NameField, value) != true)) | |
| { | |
| this.NameField = value; | |
| this.RaisePropertyChanged("Name"); | |
| } | |
| } | |
| } | |
| public ObservableCollection<ProjectPortfolio> ProjectPortfolio { get; set; } | |
| public override string ToString() | |
| { | |
| return Name; | |
| } | |
| public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; | |
| public void RaisePropertyChanged(string propertyName) | |
| { | |
| System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged; | |
| if ((propertyChanged != null)) | |
| { | |
| propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); | |
| } | |
| } | |
| } | |
| public class ProjectPortfolio : INotifyPropertyChanged | |
| { | |
| ProjectPortfolioType _type; | |
| public ProjectPortfolio(ProjectPortfolioType type) | |
| { | |
| _type = type; | |
| } | |
| public int ID { get; set; } | |
| public string NameField = ""; | |
| public string Name2 | |
| { | |
| get | |
| { | |
| return this.NameField; | |
| } | |
| set | |
| { | |
| if ((object.ReferenceEquals(this.NameField, value) != true)) | |
| { | |
| this.NameField = value; | |
| this.RaisePropertyChanged("Name2"); | |
| _type.RaisePropertyChanged("ProjectPortfolio"); | |
| } | |
| } | |
| } | |
| public string Desc { get; set; } | |
| public int ProjectLinksCount { get; set; } | |
| public override string ToString() | |
| { | |
| return Name2; | |
| } | |
| public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; | |
| protected void RaisePropertyChanged(string propertyName) | |
| { | |
| System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged; | |
| if ((propertyChanged != null)) | |
| { | |
| propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); | |
| } | |
| } | |
| } | |
| } | |
| <UserControl x:Class="Telerik_Quick_Test.Page" | |
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
| xmlns:TC="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" | |
| xmlns:TC_Nav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" | |
| > | |
| <UserControl.Resources> | |
| <DataTemplate x:Key="template2"> | |
| <TextBlock Text="{Binding Name2,Mode=TwoWay}" /> | |
| </DataTemplate> | |
| <TC:HierarchicalDataTemplate x:Key="template1" ItemTemplate="{StaticResource template2}" ItemsSource="{Binding ProjectPortfolio, Mode=TwoWay}"> | |
| <TextBlock Text="{Binding Name, Mode=TwoWay}" /> | |
| </TC:HierarchicalDataTemplate> | |
| </UserControl.Resources> | |
| <Grid x:Name="LayoutRoot" Margin="10"> | |
| <Grid.ColumnDefinitions> | |
| <ColumnDefinition Width="1*" /> | |
| <ColumnDefinition Width="1*" /> | |
| </Grid.ColumnDefinitions> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="1*" /> | |
| </Grid.RowDefinitions> | |
| <TC_Nav:RadTreeView x:Name="PortfolioTree" Grid.Column="0" IsEditable="True" ItemTemplate="{StaticResource template1}"> | |
| </TC_Nav:RadTreeView> | |
| <ItemsControl x:Name="itemsControl1" Grid.Column="1"> | |
| <ItemsControl.ItemTemplate> | |
| <DataTemplate> | |
| <TextBox Text="{Binding Name2,Mode=TwoWay}"/> | |
| </DataTemplate> | |
| </ItemsControl.ItemTemplate> | |
| </ItemsControl> | |
| </Grid> | |
| </UserControl> | |

