New to Telerik UI for WPF? Start a free 30-day trial
Add a new treeview item with a default name in edit mode
Updated on Sep 15, 2025
Environment
| Product | RadTreeView for WPF |
Description
How to allow the user to edit an item that is added to the RadTreeView.
Solution
Make sure that the IsInEditMode property of the item is set to True after the RadTreeViewItem is loaded. Examples 1 and 2 demonstrate how you can achieve that in an MVVM scenario.
Example 1 demonstrates a sample implementation of a model and a viewmodel that contains a collection of models as well as a command for adding new items.
Example 1: The Model and ViewModel
C#
public class Team : ViewModelBase
{
private string name = "";
private bool isInEditMode;
public string Name
{
get { return this.name; }
set
{
if (this.name != value)
{
this.name = value;
this.OnPropertyChanged("Name");
}
}
}
public bool IsInEditMode
{
get
{
return this.isInEditMode;
}
set
{
if (this.isInEditMode != value)
{
this.isInEditMode = value;
this.OnPropertyChanged("IsInEditMode");
}
}
}
public static ObservableCollection<Team> GetTeams()
{
var teams = new ObservableCollection<Team>();
for (int i = 0; i < 5; i++)
{
teams.Add(new Team() { Name = "Team " + i });
}
return teams;
}
}
public class ViewModel
{
private ObservableCollection<Team> teams;
public ViewModel()
{
this.AddItemCommand = new DelegateCommand(OnAddItem);
}
public DelegateCommand AddItemCommand { get; }
public ObservableCollection<Team> Teams
{
get
{
if (this.teams == null)
{
this.teams = Team.GetTeams();
}
return this.teams;
}
}
private void OnAddItem(object obj)
{
var itemToAdd = new Team() { Name = "Added from button" };
this.Teams.Add(itemToAdd);
// We need to make sure that the new item is loaded before it enters edit mode
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
itemToAdd.IsInEditMode = true;
}), DispatcherPriority.Loaded);
}
}Example 2 shows how the RadTreeView is setup. Note, that the ItemEditTemplate is set along with a style binding the IsInEditMode property of the RadTreeViewItem to the property in our model.
Example 2: The view
XAML
<Grid>
<Grid.DataContext>
<local:ViewModel />
</Grid.DataContext>
<Grid.Resources>
<DataTemplate x:Key="ItemEditTemplate">
<TextBox Text="{Binding Name}" />
</DataTemplate>
<!-- If you are using the NoXaml dlls, you should base the style on the default one for the theme like so-->
<!-- <Style TargetType="telerik:RadTreeViewItem" BasedOn="{StaticResource RadTreeViewItemStyle}"> -->
<Style TargetType="telerik:RadTreeViewItem" >
<Setter Property="IsInEditMode" Value="{Binding IsInEditMode}" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<Button Content="Add item in edit mode" Command="{Binding AddItemCommand}" />
<telerik:RadTreeView Grid.Row="1"
ItemEditTemplate="{StaticResource ItemEditTemplate}"
IsEditable="True"
IsVirtualizing="True"
DisplayMemberPath="Name"
ItemsSource="{Binding Teams}">
</telerik:RadTreeView>
</Grid>
Figure 1: Result after the add button is clicked in the Fluent theme
