Using WPF, I have a ListBox control with a DataTemplate inside it. The relevant XAML code is shown below:
If I may supplement, in order to cover the (double) part of the original question, in Youngjae's reply you make the following replacement in the xaml file:
is replaced with
adding also the proper RoutedCommand in UserControl.Resources
and a CommandBinding in UserControl.CommandBindings
Also in the code behind file:
private void textBlockName_MouseDown(object sender, MouseButtonEventArgs e)
{
var grid = ((Grid) ((TextBlock) sender).Parent);
var tbx = (TextBox)grid.Children[1];
((TextBlock)sender).Visibility = Visibility.Collapsed;
tbx.Visibility = Visibility.Visible;
this.Dispatcher.BeginInvoke((Action)(() => Keyboard.Focus(tbx)), DispatcherPriority.Render);
}
is replaced by
private void CmdEditTextblock_Executed(object sender, ExecutedRoutedEventArgs e)
{
var grid = ((Grid)((TextBlock)e.OriginalSource).Parent);
var tbx = (TextBox)grid.Children[1];
((TextBlock)e.OriginalSource).Visibility = Visibility.Collapsed;
tbx.Visibility = Visibility.Visible;
this.Dispatcher.BeginInvoke((Action)(() => Keyboard.Focus(tbx)), DispatcherPriority.Render);
}
In case some people want to have left doubleclick as input gesture, like I did...