This question is locked. New answers and comments are not allowed.
Hi,
I created a simple application (runs out of browser) to show RadTreeView with ability to change node name. A simple click on RadTreeViewItem should select node and the second click on same node should enter node name to edit mode. It works perfect! But... after it I created another application containing a simple button only. And this button should launch the first application with RadTreeView. And ... "something happens" - the selection works as well and edit mode is entered but after it "something" steals focus and edit mode is finished exactly after beginning. How this problem could be resolved?
A code is following:
RafTreeView application
I created a simple application (runs out of browser) to show RadTreeView with ability to change node name. A simple click on RadTreeViewItem should select node and the second click on same node should enter node name to edit mode. It works perfect! But... after it I created another application containing a simple button only. And this button should launch the first application with RadTreeView. And ... "something happens" - the selection works as well and edit mode is entered but after it "something" steals focus and edit mode is finished exactly after beginning. How this problem could be resolved?
A code is following:
RafTreeView application
A code behind of View - RadTreeViewDemo.xaml.cs :publicpartialclassRadTreeViewDemo : UserControl{publicRadTreeViewDemo(TreeViewModel viewModel){InitializeComponent();DataContext = viewModel;}privateScenario selectedItem;privatevoidListTreeView_MouseLeftButtonUp(objectsender, MouseButtonEventArgs e){if( e.OriginalSourceisTextBlock ){if( ( e.OriginalSourceasTextBlock ).DataContextisScenario ){Scenario newSelectedItem = ( e.OriginalSourceasTextBlock ).DataContextasScenario;if(this.selectedItem != newSelectedItem ){if(this.selectedItem !=null){this.selectedItem.IsEditable =false;}this.selectedItem = newSelectedItem;}else{this.selectedItem.IsEditable =true;}}}}}
A View - RadTreeViewDemo.xaml :<UserControlx:Class="RadControlsSilverlightApp1.RadTreeViewDemo"xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"xmlns:Application="clr-namespace:RadControlsSilverlightApp1"mc:Ignorable="d"d:DesignWidth="640"d:DesignHeight="480"><UserControl.Resources><ResourceDictionary><Stylex:Key="DefaultRadTreeViewStyle"TargetType="telerik:RadTreeView"><SetterProperty="telerik:AnimationManager.AnimationSelector"><Setter.Value><telerik:AnimationSelector><telerik:TreeViewExpandCollapseAnimationAnimationName="Expand"Direction="In"/><telerik:TreeViewExpandCollapseAnimationAnimationName="Collapse"Direction="Out"/></telerik:AnimationSelector></Setter.Value></Setter><SetterProperty="SelectionMode"Value="Single"/><SetterProperty="ItemEditTemplate"><Setter.Value><DataTemplate><TextBox/></DataTemplate></Setter.Value></Setter><SetterProperty="Template"><Setter.Value><ControlTemplateTargetType="telerik:RadTreeView"><Gridx:Name="RootElement"><BorderBorderBrush="Black"BorderThickness="1"Background="Blue"><Grid><ScrollViewerx:Name="ScrollViewer"><ItemsPresenter/></ScrollViewer><Gridx:Name="DragBetweenItemsFeedback"HorizontalAlignment="Left"Height="8"IsHitTestVisible="False"Margin="{TemplateBinding Padding}"Visibility="Collapsed"VerticalAlignment="Top"><Grid.ColumnDefinitions><ColumnDefinitionWidth="8"/><ColumnDefinition/></Grid.ColumnDefinitions><EllipseHorizontalAlignment="Left"Height="8"Stroke="{StaticResource DragBetweenItemsFeedback_BackgroundBrush}"StrokeThickness="2"VerticalAlignment="Center"Width="8"/><RectangleGrid.Column="1"Fill="{StaticResource DragBetweenItemsFeedback_BackgroundBrush}"Height="2"Margin="-2,3,0,0"RadiusY="2"RadiusX="2"VerticalAlignment="Top"/></Grid></Grid></Border></Grid></ControlTemplate></Setter.Value></Setter></Style><telerik:ContainerBindingCollectionx:Key="TreeViewItemContainerBinding"><telerik:ContainerBindingPropertyName="IsInEditMode"Binding="{Binding IsEditable, Mode=TwoWay}"/><telerik:ContainerBindingPropertyName="IsExpanded"Binding="{Binding IsExpanded, Mode=TwoWay}"/></telerik:ContainerBindingCollection><telerik:HierarchicalDataTemplatex:Key="ScenarioDefinitionItemTemplate"telerik:ContainerBinding.ContainerBindings="{StaticResource TreeViewItemContainerBinding}"><StackPanelOrientation="Horizontal"><TextBlockx:Name="Title"Text="{Binding Name, Mode=TwoWay}"VerticalAlignment="Center"HorizontalAlignment="Left"Width="30"TextTrimming="WordEllipsis"Margin="5,0,0,0"></TextBlock></StackPanel></telerik:HierarchicalDataTemplate><!-- TreeView Common Style --><Stylex:Key="CommonInputFilesTreeViewStyle"TargetType="telerik:RadTreeView"BasedOn="{StaticResource DefaultRadTreeViewStyle}"><SetterProperty="BorderBrush"Value="Black"/><SetterProperty="Background"Value="DarkGrey"/><SetterProperty="SelectionMode"Value="Extended"/><SetterProperty="IsDragDropEnabled"Value="True"/><SetterProperty="ItemsIndent"Value="20"/></Style><DataTemplatex:Key="ScenarioPathItemEditTemplate"><TextBoxText="{Binding Name, Mode=TwoWay}"FontFamily="Arial"FontSize="10"/></DataTemplate></ResourceDictionary></UserControl.Resources><Gridx:Name="LayoutRoot"Background="Azure"><telerik:RadTreeViewx:Name="ListTreeView"Background="AliceBlue"ItemsSource="{Binding ScenarioDefinitionList, Mode=TwoWay}"ItemTemplate="{StaticResource ScenarioDefinitionItemTemplate}"SelectedItem="{Binding CurrentScenario, Mode=TwoWay}"SelectionMode="Single"ItemEditTemplate="{StaticResource ScenarioPathItemEditTemplate}"IsEditable="True"MouseLeftButtonUp="ListTreeView_MouseLeftButtonUp"></telerik:RadTreeView></Grid></UserControl>A View Model TreeViewModel.cs:An entity - ScenariopublicclassTreeViewModel : INotifyPropertyChanged{publicTreeViewModel(){ScenarioDefinitionList =newObservableCollection<Scenario>(){newScenario("first"),newScenario("second"),newScenario("third"),};CurrentScenario = ScenarioDefinitionList[0];}privateObservableCollection<Scenario> scenarioDefinitionList;publicObservableCollection<Scenario> ScenarioDefinitionList{get{returnthis.scenarioDefinitionList; }set{this.scenarioDefinitionList = value;RaisePropertyChanged( () => ScenarioDefinitionList );}}privateScenario currentScenario {get;set; }publicScenario CurrentScenario{get{returnthis.currentScenario; }set{this.currentScenario = value;RaisePropertyChanged( () => CurrentScenario );}}#region INotifyPropertyChanged implementationprotectedvoidRaisePropertyChanged<T>(Expression<Func<T>> lambda){var name = PropertySupport.ExtractPropertyName<T>( lambda );NotifyPropertyChanged( name );}publicvoidNotifyPropertyChanged(stringpropertyName){var handler =this.PropertyChanged;if( handler !=null)handler(this,newPropertyChangedEventArgs( propertyName ) );}publiceventPropertyChangedEventHandler PropertyChanged;#endregion}And the second application (launcher) - xaml:publicclassScenario : INotifyPropertyChanged{publicScenario(stringname){this.Name = name;}privateboolisEditable;publicboolIsEditable{get{returnisEditable; }set{ isEditable = value;RaisePropertyChanged( () => IsEditable );}}privatestringname;publicstringName{get{returnname; }set{name = value;RaisePropertyChanged( () => Name );}}#region INotifyPropertyChanged implementationprotectedvoidRaisePropertyChanged<T>(Expression<Func<T>> lambda){var name = PropertySupport.ExtractPropertyName<T>( lambda );NotifyPropertyChanged( name );}publicvoidNotifyPropertyChanged(stringpropertyName){var handler =this.PropertyChanged;if( handler !=null)handler(this,newPropertyChangedEventArgs( propertyName ) );}publiceventPropertyChangedEventHandler PropertyChanged;#endregion}and behind code - xaml.cs:<UserControlx:Class="SilverlightApplication9.MainPage"mc:Ignorable="d"d:DesignHeight="300"d:DesignWidth="400"><Gridx:Name="LayoutRoot"Background="White"><ButtonContent="Run"Height="23"HorizontalAlignment="Left"Margin="80,49,0,0"Name="button1"VerticalAlignment="Top"Width="75"Click="button1_Click"/></Grid></UserControl>I tried it with behaviors, triggers, event handlers in code behind (as in example) and all are with same result. Could somebody advice something?publicpartialclassMainPage : UserControl{publicMainPage(){InitializeComponent();}privatevoidbutton1_Click(objectsender, RoutedEventArgs e){Window window =newWindow();TreeViewModel viewModel =newTreeViewModel();Application.Current.MainWindow.Dispatcher.BeginInvoke( () =>{RadTreeViewDemo scenarioBuilderMainView =newRadTreeViewDemo( viewModel );window.Content = scenarioBuilderMainView;} );window.Width = 1097;window.Height = 700;window.Left = ( Application.Current.Host.Content.ActualWidth - window.Width ) / 2;window.Top = ( Application.Current.Host.Content.ActualHeight - window.Height ) / 2;window.Show();}}