I have a nested treeview where I bind the doubleclik event on each item so that the text of the node is changed to an editable textbox. I then use the lostFocus eventhandler to remove the textbox and restore the text.
void treeViewItemWithMenu_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (selected == e.Source)
{
TextBox tb = new TextBox();
tb.Text = this.Header.ToString();
tb.Focus();
tb.LostFocus += new RoutedEventHandler(tb_LostFocus);
this.Header = tb;
var a = e.OriginalSource;
e.Handled = true;
}
}
void tb_LostFocus(object sender, RoutedEventArgs e)
{
this.Header = ((TextBox)(this.Header)).Text;
}
Unfortantly it does not seem like the lostFocus event is working correctly. When I click outside the textbox, it does not fire at all. I can even doubleclick on another node and it goes into edit mode (ie becomes a text box) while the first textbox seems to still have focus. Lost focus does not fire untill i start going back and forth between two text boxes.
I'm using vs2010 rc with project set to .net 3.5.