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

[Solved] Q2 Breaking Change - BeginEdit

6 Answers 228 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.
Raj
Top achievements
Rank 1
Raj asked on 21 Jul 2009, 04:46 PM
Since installing Q2 09, The RadTreeView.SelectedContainer.BeginEdit() now crashes with the exception...

Message: Object reference not set to an instance of an object.

StackTrace: 
   at Telerik.Windows.Controls.RadTreeViewItem.StartEdit()
   at Telerik.Windows.Controls.RadTreeViewItem.BeginEdit()
   at ...

Is there a workaround for this? This is one of several breaking changes I have encountered. Another is the RadTreeView's ExpandItemByPath method previously returned a RadTreeView item. It now returns void.

6 Answers, 1 is accepted

Sort by
0
Raj
Top achievements
Rank 1
answered on 21 Jul 2009, 08:11 PM
Some additional info...

Even using F2 gives the following error...

Message: Object reference not set to an instance of an object.

StackTrace: 
   at Telerik.Windows.Controls.RadTreeViewItem.StartEdit()
   at Telerik.Windows.Controls.RadTreeView.HandleF2Key(KeyEventArgs e)
   at Telerik.Windows.Controls.RadTreeView.HandleKeyDown(KeyEventArgs e)
   at Telerik.Windows.Controls.RadTreeViewItem.OnKeyDown(KeyEventArgs e)
   at System.Windows.Controls.Control.OnKeyDown(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)

I also tried changing the BeginEdit call to IsInEditMode since BeginEdit has been depracated. Still get the same error.


0
Bobi
Telerik team
answered on 22 Jul 2009, 07:21 AM
Hi Raj,

Thank you for the feedback.
Please can you send us some sample code in order to fix it. We are unable to reproduce this issue. Obviously some misconception happened.

If I understand you correctly you try to Call BeginEdit() using RadTreeView.SelectedContainer.BeginEdit() .
The reason for "Object reference not set to an instance of an object." exception is that probably SelectedContainer is null. Verify that you call BeginEdit() of valid RadTreeViewItem. However although BeginEdit() is obsolete it should not cause an exception.

As to the question about IsInEditMode you have to use it in a dispatcher.
0
Raj
Top achievements
Rank 1
answered on 22 Jul 2009, 01:48 PM
Hi Boryana - Thank you for your response. I looked into some of your suggestions. The SelectedContainer is not null. Also, I'm not explicitly setting an ItemEditTemplate. I'm using a custom ControlTemplate for the RadTreeViewItem and modified the EditElementContainer of the template. This all worked fine with the previous version of the RadControls. Am I required to set an ItemEditTemplate in the new version? Does this override the EditElementContainer of the ControlTemplate? Here's the Edit element of the template...

<!-- Edit element -->
                    <Border Visibility="Collapsed" Grid.Column="4" HorizontalAlignment="Stretch"
VerticalAlignment="Center"  Width="Auto"
Background="{StaticResource InputTextBoxBackground}"
CornerRadius="3,3,3,3"  BorderThickness="1"
x:Name="EditElementContainer"
BorderBrush="{StaticResource BorderOuterBrush}">
                        <Border Height="Auto" CornerRadius="2,2,2,2" HorizontalAlignment="Stretch"
BorderThickness="1" BorderBrush="{StaticResource BorderInnerBrush}">
                            <TextBox x:Name="EditElement" BorderThickness="0" HorizontalAlignment="Stretch" />
                        </Border>
                    </Border>

It's a bit difficult to rip the tree out of our infrastructure to give you working code i.e. removing service references and other dependancies. I'll do my best to get something to you. If you have any additional suggestions I would greatly appreciate it.

BTW, how do I attach a file to this thread in case I wanted to upload some code or a zip file with a project/solution.

Thanks,
Raj
0
Raj
Top achievements
Rank 1
answered on 22 Jul 2009, 02:54 PM

I was able to reproduce the error by modifying your "TreeView Editing" example by adding my custom ControlTemplate. I also added a button to invoke the BeginEdit method. Here is the XAML...

<UserControl x:Class="SilverlightApplication2.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    xmlns:core="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
    xmlns:input="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
    xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
    Width="400" Height="300">  
    <UserControl.Resources> 
        <Color x:Key="RadTreeView_LineColor">#FF747474</Color> 
 
        <!-- Tree View Items Style--> 
        <LinearGradientBrush x:Key="RadTreeViewSelectUnFocusFill" EndPoint="0,1">  
            <GradientStop Color="#FFf8f6f9" Offset="0" /> 
            <GradientStop Color="#FFf0f0f0" Offset="1" /> 
        </LinearGradientBrush> 
        <SolidColorBrush x:Key="RadTreeViewSelectUnFocus" Color="#FFdbdbdb" /> 
        <LinearGradientBrush x:Key="NavigationSelectedFill" EndPoint="0.5,1" StartPoint="0.5,0">  
            <GradientStop Color="#FFFEFDF1" Offset="0" /> 
            <GradientStop Color="#FFFEE699" Offset="1" /> 
            <GradientStop Color="#FFFEEBAA" Offset="0.5" /> 
            <GradientStop Color="#FFFED560" Offset="0.51" /> 
        </LinearGradientBrush> 
        <LinearGradientBrush x:Key="NavigationMouseoverFill" EndPoint="0.5,0" StartPoint="0.5,1">  
            <GradientStop Color="#FFFBF6C5" Offset="0.5"/>  
            <GradientStop Color="#FFFFFDF1" Offset="0.5"/>  
            <GradientStop Color="#FFFBFBDE" Offset="0.5"/>  
            <GradientStop Color="#FFFBFBDE" Offset="0.5"/>  
        </LinearGradientBrush> 
        <LinearGradientBrush x:Key="NavigationMouseoverStroke" EndPoint="0.5,1" StartPoint="0.5,0">  
            <GradientStop Color="#FFDBCF9C" Offset="0" /> 
            <GradientStop Color="#FFD8D1B3" Offset="1" /> 
        </LinearGradientBrush> 
        <SolidColorBrush x:Key="FocusBrushBlack" Color="#FF000000" /> 
        <SolidColorBrush x:Key="InputTextBoxBackground" Color="#FFFFFFFF" /> 
        <SolidColorBrush x:Key="BorderOuterBrush" Color="#FFFFFFFF"></SolidColorBrush> 
        <SolidColorBrush x:Key="BorderInnerBrush" Color="#FF979994" /> 
          
          
        <DataTemplate x:Key="Department">  
            <StackPanel Orientation="Horizontal">  
                <TextBlock Text="{Binding Name, Path=Name}"/>  
                <TextBlock Text=" | ID#"/>  
                <TextBlock Text="{Binding ID}"/>  
            </StackPanel> 
        </DataTemplate> 
        <core:HierarchicalDataTemplate x:Key="Organization" ItemsSource="{Binding wellList}" 
                ItemTemplate="{StaticResource Department}">  
            <StackPanel Orientation="Horizontal">  
                <TextBlock Text="{Binding Name}"/>  
                <TextBlock Text=" | ID#"/>  
                <TextBlock Text="{Binding ID}"/>  
            </StackPanel> 
        </core:HierarchicalDataTemplate> 
        <core:HierarchicalDataTemplate x:Key="PersonA" ItemsSource="{Binding batteryList}" 
                ItemTemplate="{StaticResource Organization}">  
            <StackPanel Orientation="Horizontal">  
                <TextBlock Text="{Binding Name}"/>  
                <TextBlock Text=" | ID#"/>  
                <TextBlock Text="{Binding ID}"/>  
            </StackPanel> 
        </core:HierarchicalDataTemplate> 
 
        <ControlTemplate TargetType="telerikNavigation:RadTreeViewItem" x:Key="TreeViewItemDefaultTemplate">  
            <Grid x:Name="RootElement">  
                <Grid.Resources> 
                    <SolidColorBrush x:Key="LineBrush" Color="{StaticResource RadTreeView_LineColor}"></SolidColorBrush> 
                </Grid.Resources> 
                <VisualStateManager.VisualStateGroups> 
                    <VisualStateGroup x:Name="CommonStates">  
                        <VisualState x:Name="Normal">  
                            <Storyboard></Storyboard>  
                        </VisualState> 
                        <VisualState x:Name="Disabled">  
                            <Storyboard> 
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DisabledVisual" 
                                    Storyboard.TargetProperty="Visibility" Duration="0">  
                                    <DiscreteObjectKeyFrame KeyTime="0">  
                                        <DiscreteObjectKeyFrame.Value> 
                                            <Visibility>Visible</Visibility> 
                                        </DiscreteObjectKeyFrame.Value> 
                                    </DiscreteObjectKeyFrame> 
                                </ObjectAnimationUsingKeyFrames> 
 
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" 
                                    Storyboard.TargetName="Header" To="0.35" Duration="0:0:0.0" /> 
 
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" 
                                    Storyboard.TargetName="Image" To="0.35" Duration="0:0:0.0" /> 
                            </Storyboard> 
                        </VisualState> 
                        <VisualState x:Name="MouseOver">  
                            <Storyboard> 
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" 
                                    Storyboard.TargetName="MouseOverVisual" To="0.9" 
                                    Duration="0:0:0.1" /> 
                            </Storyboard> 
                        </VisualState> 
                    </VisualStateGroup> 
                    <VisualStateGroup x:Name="SelectionStates">  
                        <VisualState x:Name="Unselected">  
                            <Storyboard> 
 
                            </Storyboard> 
                        </VisualState> 
                        <VisualState x:Name="Selected">  
                            <Storyboard> 
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectionVisual" 
                                    Storyboard.TargetProperty="Visibility" Duration="0">  
                                    <DiscreteObjectKeyFrame KeyTime="0">  
                                        <DiscreteObjectKeyFrame.Value> 
                                            <Visibility>Visible</Visibility> 
                                        </DiscreteObjectKeyFrame.Value> 
                                    </DiscreteObjectKeyFrame> 
                                </ObjectAnimationUsingKeyFrames> 
                            </Storyboard> 
                        </VisualState> 
                        <VisualState x:Name="SelectedUnfocused">  
                            <Storyboard> 
                                <ObjectAnimationUsingKeyFrames  
                                    Storyboard.TargetName="SelectionUnfocusedVisual" 
                                    Storyboard.TargetProperty="Visibility" Duration="0">  
                                    <DiscreteObjectKeyFrame KeyTime="0">  
                                        <DiscreteObjectKeyFrame.Value> 
                                            <Visibility>Visible</Visibility> 
                                        </DiscreteObjectKeyFrame.Value> 
                                    </DiscreteObjectKeyFrame> 
                                </ObjectAnimationUsingKeyFrames> 
                            </Storyboard> 
                        </VisualState> 
                    </VisualStateGroup> 
                    <VisualStateGroup x:Name="LoadingOnDemandStates">  
                        <VisualState x:Name="LoadingOnDemand">  
                            <Storyboard> 
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LoadingVisual" 
                                    Storyboard.TargetProperty="Visibility" Duration="0">  
                                    <DiscreteObjectKeyFrame KeyTime="0">  
                                        <DiscreteObjectKeyFrame.Value> 
                                            <Visibility>Visible</Visibility> 
                                        </DiscreteObjectKeyFrame.Value> 
                                    </DiscreteObjectKeyFrame> 
                                </ObjectAnimationUsingKeyFrames> 
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Expander" 
                                    Storyboard.TargetProperty="Visibility" Duration="0">  
                                    <DiscreteObjectKeyFrame KeyTime="0">  
                                        <DiscreteObjectKeyFrame.Value> 
                                            <Visibility>Collapsed</Visibility> 
                                        </DiscreteObjectKeyFrame.Value> 
                                    </DiscreteObjectKeyFrame> 
                                </ObjectAnimationUsingKeyFrames> 
                                <DoubleAnimation From="0" To="359" Duration="0:0:1" 
                                    RepeatBehavior="Forever" 
                                    Storyboard.TargetName="LoadingVisualAngleTransform" 
                                    Storyboard.TargetProperty="Angle" /> 
                            </Storyboard> 
                        </VisualState> 
                        <VisualState x:Name="LoadingOnDemandReverse">  
                            <Storyboard> 
 
                            </Storyboard> 
                        </VisualState> 
                    </VisualStateGroup> 
                    <VisualStateGroup x:Name="FocusStates">  
                        <VisualState x:Name="Focused">  
                            <Storyboard> 
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" 
                                    Storyboard.TargetProperty="Visibility" Duration="0">  
                                    <DiscreteObjectKeyFrame KeyTime="0">  
                                        <DiscreteObjectKeyFrame.Value> 
                                            <Visibility>Visible</Visibility> 
                                        </DiscreteObjectKeyFrame.Value> 
                                    </DiscreteObjectKeyFrame> 
                                </ObjectAnimationUsingKeyFrames> 
                            </Storyboard> 
                        </VisualState> 
                        <VisualState x:Name="Unfocused">  
                            <Storyboard> 
 
                            </Storyboard> 
                        </VisualState> 
                    </VisualStateGroup> 
                    <VisualStateGroup x:Name="ExpandStates">  
                    </VisualStateGroup> 
                </VisualStateManager.VisualStateGroups> 
                <Grid.RowDefinitions> 
                    <RowDefinition Height="Auto" /> 
                    <RowDefinition /> 
                </Grid.RowDefinitions> 
                <Border Background="{TemplateBinding Background}" 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}">  
                    <Grid x:Name="HeaderRow" Background="Transparent" 
                        MinHeight="{TemplateBinding MinHeight}">  
 
                        <Grid.ColumnDefinitions> 
                            <!-- indent --> 
                            <ColumnDefinition Width="Auto" /> 
 
                            <!-- collapse/expand --> 
                            <ColumnDefinition Width="Auto" /> 
 
                            <!-- checkbox, radio--> 
                            <ColumnDefinition Width="Auto" /> 
 
                            <!-- left image --> 
                            <ColumnDefinition Width="Auto" /> 
 
                            <!-- selection, text, edit element --> 
                            <ColumnDefinition Width="Auto" /> 
 
                            <!-- empty --> 
                            <ColumnDefinition Width="*" /> 
 
                        </Grid.ColumnDefinitions> 
 
                        <!-- Selection Unfocused--> 
                        <Rectangle x:Name="SelectionUnfocusedVisual" RadiusX="2" RadiusY="2" 
                            Fill="{StaticResource RadTreeViewSelectUnFocusFill}" 
                            Stroke="{StaticResource RadTreeViewSelectUnFocus}" Grid.Column="2" 
                            Grid.ColumnSpan="6"   
                            Visibility="Collapsed" /> 
 
                        <!-- Selection --> 
                        <Rectangle x:Name="SelectionVisual" Fill="{StaticResource NavigationSelectedFill}" 
                            Stroke="{StaticResource NavigationMouseoverStroke}" RadiusX="2" 
                            RadiusY="2" Grid.Column="2" Grid.ColumnSpan="6"   
                            Visibility="Collapsed" /> 
 
                        <!-- MouseOver  --> 
                        <Rectangle x:Name="MouseOverVisual" Grid.Column="2" Grid.ColumnSpan="6"   
                            Opacity="0" Fill="{StaticResource NavigationMouseoverFill}" 
                            Stroke="{StaticResource NavigationMouseoverStroke}" RadiusX="2" 
                            RadiusY="2" /> 
 
                        <!-- indent --> 
                        <StackPanel x:Name="IndentContainer" Orientation="Horizontal" Opacity="0.2">  
                            <Rectangle x:Name="IndentFirstVerticalLine" Width="1" Visibility="Collapsed" 
                                Stroke="{StaticResource LineBrush}" VerticalAlignment="Top">  
                                <Rectangle.Clip> 
                                    <RectangleGeometry Rect="0,0,1,10000" /> 
                                </Rectangle.Clip> 
                            </Rectangle> 
                        </StackPanel> 
 
                        <!-- ListRoot decoration --> 
                        <Grid Grid.Column="1" x:Name="ListRootContainer" HorizontalAlignment="Center" 
                            MinWidth="20">  
 
                            <!-- Lines --> 
                            <Rectangle x:Name="HorizontalLine" Opacity="0.2" Height="1" 
                                Stroke="{StaticResource LineBrush}" VerticalAlignment="Center" 
                                HorizontalAlignment="Right">  
                                <Rectangle.Clip> 
                                    <RectangleGeometry Rect="0,0,10000,1" /> 
                                </Rectangle.Clip> 
                            </Rectangle> 
                            <Rectangle x:Name="VerticalLine" Opacity="0.2" Width="1" 
                                Stroke="{StaticResource LineBrush}" VerticalAlignment="Top" 
                                HorizontalAlignment="Center">  
                                <Rectangle.Clip> 
                                    <RectangleGeometry Rect="0,0,1,10000" /> 
                                </Rectangle.Clip> 
                            </Rectangle> 
 
                            <!-- Collapse/Expand --> 
                            <ToggleButton x:Name="Expander" IsTabStop="False" 
                                Background="{TemplateBinding Background}" /> 
 
                            <!-- Loading ... --> 
                            <Grid x:Name="LoadingVisual" RenderTransformOrigin="0.5,0.5" 
                                Visibility="Collapsed" VerticalAlignment="Center" 
                                HorizontalAlignment="Center">  
                                <Grid.RenderTransform> 
                                    <TransformGroup> 
                                        <RotateTransform x:Name="LoadingVisualAngleTransform" Angle="0" 
                                            CenterX="0.5" CenterY="0.5" /> 
                                    </TransformGroup> 
                                </Grid.RenderTransform> 
                                <Path Width="10" Height="10" Stretch="Fill" 
                                    Stroke="{TemplateBinding Foreground}" StrokeThickness="1" 
                                    StrokeStartLineCap="Round" Data="M1,0 A1,1,90,1,1,0,-1" /> 
 
                                <Path Margin="5,-1.5,0,0" HorizontalAlignment="Left" 
                                    VerticalAlignment="Top" Width="4" Height="4" Stretch="Fill" 
                                    Fill="{TemplateBinding Foreground}" 
                                    Data="M0,-1.1 L0.1,-1 L0,-0.9" StrokeThickness="1" /> 
                            </Grid> 
 
                        </Grid> 
                        <!--/ ListRoot decoration --> 
 
                        <!-- Checkbox/Radio --> 
                        <CheckBox IsTabStop="False" Grid.Column="5" VerticalAlignment="Center" HorizontalAlignment="Right" 
                            Margin="2,0,0,0" x:Name="CheckBoxElement" Visibility="Collapsed"></CheckBox> 
 
                        <RadioButton IsTabStop="False" Grid.Column="2" Margin="2,0,0,0" 
                            VerticalAlignment="Center" x:Name="RadioButtonElement" 
                            Visibility="Collapsed"></RadioButton> 
                        <!--/ Checkbox/Radio --> 
 
                        <!-- Image and text --> 
                        <Image Grid.Column="3" x:Name="Image" Source="{TemplateBinding DefaultImageSrc}" 
                            MaxWidth="16" MaxHeight="16" Margin="2" HorizontalAlignment="Center" 
                            VerticalAlignment="Center" /> 
 
                        <!-- Focus --> 
                        <Rectangle x:Name="FocusVisual" Visibility="Collapsed" Grid.Column="2" 
                            Grid.ColumnSpan="6" Stroke="{StaticResource FocusBrushBlack}" 
                            StrokeThickness="1" StrokeDashArray="1 2" IsHitTestVisible="False" 
                            RadiusX="2" RadiusY="2" Margin="1" /> 
 
                        <!-- Content --> 
                        <ContentPresenter x:Name="Header" Grid.Column="4" 
                            Content="{TemplateBinding Header}" 
                            ContentTemplate="{TemplateBinding HeaderTemplate}" 
                            HorizontalAlignment="Left" VerticalAlignment="Center" Margin="1 0 5 0" /> 
 
                        <!-- Edit element --> 
                        <Border Visibility="Collapsed" Grid.Column="4" HorizontalAlignment="Stretch" 
                            VerticalAlignment="Center"  Width="Auto" 
                            Background="{StaticResource InputTextBoxBackground}" 
                            CornerRadius="3,3,3,3"  BorderThickness="1" 
                            x:Name="EditElementContainer" 
                            BorderBrush="{StaticResource BorderOuterBrush}">  
                            <Border Height="Auto" CornerRadius="2,2,2,2" HorizontalAlignment="Stretch" 
                                BorderThickness="1" BorderBrush="{StaticResource BorderInnerBrush}">  
                                <TextBox x:Name="EditElement" BorderThickness="0" HorizontalAlignment="Stretch" /> 
                            </Border> 
                        </Border> 
 
                        <!-- Disabled --> 
                        <Rectangle x:Name="DisabledVisual" Grid.Column="2" Grid.ColumnSpan="3" 
                            IsHitTestVisible="true" Visibility="Collapsed" /> 
 
                    </Grid> 
                </Border> 
 
                <!-- Items Container --> 
                <ItemsPresenter Grid.Row="1" x:Name="ItemsHost" Visibility="Collapsed" VerticalAlignment="Bottom"/>  
                <!--/ Items Container --> 
 
            </Grid> 
        </ControlTemplate> 
 
        <Style TargetType="telerikNavigation:RadTreeViewItem" x:Key="TreeViewItemStyle">  
            <Setter Property="CheckState" Value="Off" /> 
            <Setter Property="IsDropAllowed" Value="True" /> 
            <Setter Property="ItemsOptionListType" Value="CheckList" /> 
            <Setter Property="IsEnabled" Value="True" /> 
            <Setter Property="MinHeight" Value="20" /> 
            <Setter Property="Template" Value="{StaticResource TreeViewItemDefaultTemplate}" /> 
            <Setter Property="ItemsPanel">  
                <Setter.Value> 
                    <ItemsPanelTemplate> 
                        <StackPanel VerticalAlignment="Bottom" /> 
                    </ItemsPanelTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 
 
    </UserControl.Resources> 
    <Grid x:Name="LayoutRoot" Background="White">  
        <StackPanel Orientation="Vertical">  
        <Border BorderBrush="#FF000000" CornerRadius="5" BorderThickness="5" Background="#FFFFFFFF">  
            <telerikNavigation:RadTreeView x:Name="treeView"  IsEditable="true" HorizontalAlignment="Left" 
                    VerticalAlignment="Top" IsLineEnabled="True" ItemTemplate="{StaticResource PersonA}" ItemContainerStyle="{StaticResource TreeViewItemStyle}">  
                <telerikNavigation:RadTreeView.ItemEditTemplate> 
                    <DataTemplate> 
                        <StackPanel Orientation="Horizontal">  
                            <TextBox Text="{Binding Name, Mode=TwoWay}" /> 
                            <input:RadMaskedTextBox Value="{Binding ID, Mode=TwoWay}" MaskType="Numeric" Mask="#"/>  
                        </StackPanel> 
                    </DataTemplate> 
                </telerikNavigation:RadTreeView.ItemEditTemplate> 
            </telerikNavigation:RadTreeView> 
        </Border> 
            <Button Click="Button_Click" Width="100" Content="Edit" Margin="5"/>  
        </StackPanel> 
    </Grid> 
</UserControl> 
 

Here is the code-behind. the only change here is the button click event handler...

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Documents;  
using System.Windows.Input;  
using System.Windows.Media;  
using System.Windows.Media.Animation;  
using System.Windows.Shapes;  
using System.ComponentModel;  
 
namespace SilverlightApplication2  
{  
    public partial class Page : UserControl  
    {  
        public Page()  
        {  
            InitializeComponent();  
            this.treeView.ItemsSource = new TreeDataSource();  
        }  
 
        private void Button_Click(object sender, RoutedEventArgs e)  
        {  
            try  
            {  
                this.treeView.SelectedContainer.BeginEdit();  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);  
            }  
        }  
    }  
 
    public class Organization : INotifyPropertyChanged  
    {  
        private static int uid = 0;  
        private string name;  
        private string id;  
        public Organization(string name)  
        {  
            Name = name;  
            ID = (++uid).ToString();  
            batteryList = new List<Department>();  
        }  
        public string Name  
        {  
            get { return this.name; }  
 
            set  
            {  
                if (value != this.name)  
                {  
                    this.name = value;  
                    this.NotifyPropertyChanged("Name");  
                }  
            }  
        }  
 
        public string ID  
        {  
            get { return id; }  
 
            set  
            {  
                if (value != id)  
                {  
                    id = value;  
                    this.NotifyPropertyChanged("ID");  
                }  
            }  
        }  
 
        public List<Department> batteryList { get; set; }  
 
        public event PropertyChangedEventHandler PropertyChanged;  
 
        private void NotifyPropertyChanged(string info)  
        {  
            if (PropertyChanged != null)  
            {  
                PropertyChanged(this, new PropertyChangedEventArgs(info));  
            }  
        }  
 
    }  
    public class Department : INotifyPropertyChanged  
    {  
        private string name;  
        private string id;  
        private static int uid = 0;  
        public Department(string name)  
        {  
            Name = name;  
            ID = (++uid).ToString();  
            wellList = new List<Person>();  
        }  
        public string Name  
        {  
            get { return this.name; }  
 
            set  
            {  
                if (value != this.name)  
                {  
                    this.name = value;  
                    this.NotifyPropertyChanged("Name");  
                }  
            }  
        }  
        public string ID  
        {  
            get { return id; }  
 
            set  
            {  
                if (value != id)  
                {  
                    id = value;  
                    this.NotifyPropertyChanged("ID");  
                }  
            }  
        }  
        public List<Person> wellList { get; set; }  
 
        #region INotifyPropertyChanged Members  
 
        public event PropertyChangedEventHandler PropertyChanged;  
 
        private void NotifyPropertyChanged(string info)  
        {  
            if (PropertyChanged != null)  
            {  
                PropertyChanged(this, new PropertyChangedEventArgs(info));  
            }  
        }  
 
        #endregion  
    }  
    public class Person : INotifyPropertyChanged  
    {  
        private string name;  
        private string id;  
        private static int uid = 0;  
        public Person(string name)  
        {  
 
            Name = name;  
            ID = (++uid).ToString();  
        }  
 
        public string Name  
        {  
            get { return this.name; }  
 
            set  
            {  
                if (value != this.name)  
                {  
                    this.name = value;  
                    this.NotifyPropertyChanged("Name");  
                }  
            }  
        }  
        public string ID  
        {  
            get { return id; }  
 
            set  
            {  
                if (value != id)  
                {  
                    id = value;  
                    this.NotifyPropertyChanged("ID");  
                }  
            }  
        }  
 
        public event PropertyChangedEventHandler PropertyChanged;  
        private void NotifyPropertyChanged(string info)  
        {  
            if (PropertyChanged != null)  
            {  
                PropertyChanged(this, new PropertyChangedEventArgs(info));  
            }  
        }  
    }  
    public class TreeDataSource : List<Organization> 
    {  
        public TreeDataSource()  
        {  
            Organization treeArea;  
            Department d;  
            Add(treeArea = new Organization("Organization  A-B"));  
            treeArea.batteryList.Add((d = new Department("Department  A")));  
            d.wellList.Add(new Person("John"));  
            d.wellList.Add(new Person("Ben"));  
            d.wellList.Add(new Person("George"));  
            d.wellList.Add(new Person("Peter"));  
            d.wellList.Add(new Person("Ann"));  
            treeArea.batteryList.Add((d = new Department("Department  B")));  
            d.wellList.Add(new Person("Katy"));  
            d.wellList.Add(new Person("Karoline"));  
            d.wellList.Add(new Person("Simone"));  
            d.wellList.Add(new Person("Eduard"));  
            d.wellList.Add(new Person("Steave"));  
            Add(treeArea = new Organization("Organization  B-C"));  
            treeArea.batteryList.Add((d = new Department("Department  C")));  
            d.wellList.Add(new Person("Bob"));  
            d.wellList.Add(new Person("Smith"));  
            d.wellList.Add(new Person("Alex"));  
            treeArea.batteryList.Add((d = new Department("Department  D")));  
            d.wellList.Add(new Person("Katya"));  
            d.wellList.Add(new Person("Robert"));  
        }  
    }  
}  
 

I can also upload a zip file of the solution if you think it's helpfull.

Thanks,
Raj

0
Raj
Top achievements
Rank 1
answered on 22 Jul 2009, 04:06 PM
I think I found a solution to this. It seems that the control template I created from the previous version is incompatible with the new version of the TreeView. I extracted the control template for the new version and modified that to add my custom settings. This seemed to resolve the issue.
0
Bobi
Telerik team
answered on 23 Jul 2009, 08:25 AM
Hi Raj,

I am glad to hear that you have found a solution to your problem.
Please do not hesitate to ask if you have further questions.



Best wishes,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
Raj
Top achievements
Rank 1
Answers by
Raj
Top achievements
Rank 1
Bobi
Telerik team
Share this question
or