I have a model class, Folder:
This is exposed to the UI via a view model, the the folder structure is displayed in a RadTreeView using a hierarchical data template and all is well.
I am adding a context menu to each Folder in the tree view, one of the options on the menu is "Rename". When this is clicked, I want the relevant RadTreeViewItem to go into edit mode.
I can add an "IsInEditMode" flag to the Folder, that's not a problem. The Command on the menu item is bound to the command on the view model, and I can get hold of the relevant Folder using a command parameter, that's not a problem.
But how to I set the IsEditable on the hierarchical data template? And how do I bind the IsInEditMode of the TreeViewItem to that of the Folder? Here is my current XAML (which shows a few other things, like a similar structure with the Tag objects:
Open to other suggestions. Cheers.
public
class
Folder
{
public
string
Name {
get
;
set
; }
public
ObservableCollection<Folder> SubFolders {
get
;
set
; }
}
This is exposed to the UI via a view model, the the folder structure is displayed in a RadTreeView using a hierarchical data template and all is well.
I am adding a context menu to each Folder in the tree view, one of the options on the menu is "Rename". When this is clicked, I want the relevant RadTreeViewItem to go into edit mode.
I can add an "IsInEditMode" flag to the Folder, that's not a problem. The Command on the menu item is bound to the command on the view model, and I can get hold of the relevant Folder using a command parameter, that's not a problem.
But how to I set the IsEditable on the hierarchical data template? And how do I bind the IsInEditMode of the TreeViewItem to that of the Folder? Here is my current XAML (which shows a few other things, like a similar structure with the Tag objects:
<
telerik:RadTreeView
DockPanel.Dock
=
"Top"
>
<
telerik:RadTreeViewItem
Header
=
"My Folders"
ItemsSource
=
"{Binding Folders}"
>
<
telerik:RadTreeViewItem.ItemTemplate
>
<
HierarchicalDataTemplate
ItemsSource
=
"{Binding SubFolders}"
DataType
=
"{x:Type Model:Folder}"
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
HierarchicalDataTemplate
>
</
telerik:RadTreeViewItem.ItemTemplate
>
</
telerik:RadTreeViewItem
>
</
telerik:RadTreeView
>
<
telerik:RadTreeView
DockPanel.Dock
=
"Top"
>
<
telerik:RadTreeViewItem
Header
=
"My Tags"
ItemsSource
=
"{Binding Tags}"
>
<
telerik:RadTreeViewItem.ItemTemplate
>
<
HierarchicalDataTemplate
ItemsSource
=
"{Binding SubTags}"
DataType
=
"{x:Type Model:Tag}"
>
<
TextBlock
Text
=
"{Binding Name}"
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
>
<
telerik:RadMenuItem
Header
=
"Rename"
Command
=
"{StaticResource renameTagCommand}"
CommandParameter
=
"{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
/>
<
telerik:RadMenuItem
Header
=
"Delete Tag"
/>
</
telerik:RadContextMenu
>
</
telerik:RadContextMenu.ContextMenu
>
</
TextBlock
>
</
HierarchicalDataTemplate
>
</
telerik:RadTreeViewItem.ItemTemplate
>
</
telerik:RadTreeViewItem
>
Open to other suggestions. Cheers.