I would like to enable editing an item in TreeView
just in two cases:
- when a user clicks at
Edit
button inContextMenu
ofTreeView
- when a user click
F2
at the selected item of TreeView.
My xaml of TreeView
:
<TreeView ItemsSource="{Binding FooColl}" >
<TreeView.Resources>
<DiscreteObjectKeyFrame x:Key="proxy" Value="{Binding}"/>
<HierarchicalDataTemplate DataType="{x:Type treeViewModel:NodeViewModel}"
ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Image Source="treeNode.png" />
<TextBlock Text="{Binding FooValue}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Edit"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
My first thought was to use TextBox
instead of TextBlock
in HierarchicalDataTemplate
. However, the edit mode of TextBox
is enabled by MouseClick
. Consequently, it is not what I want.
Any thoughts about how can I do that?