To reproduce:
1. Create a XamDataTree with some nodes, set AllowEditing to true.2. Run and hit F2 to rename a node (but do not confirm by hitting Enter or clicking outside the TextBox).3. Alt-Tab away and then back.4. The TextBox is still there, the node is still in editing mode.
Instead of step 3, you can add a XamDockManager to the app, create a floating pane and from the node editor TextBox click into the floating pane. The TextBox does not disappear.
Questions:
1. Is this the intended behavior (I would expect a behavior similar to the windows explorer, Alt-Tab confirms the current value in the TextBox)?
2. If no, could you fix it please.
3. If yes, is there an easy way to achieve that Alt-Tab or clicking into a floating pane confirms the value in the TextBox and the node automatically leaves edinting mode?
Hello Tjark,
Thank you for sharing your solution. I think other community members can benefit from this.
I created this Blend behavior to solve my problem (it selects all text on entering edit mode and exits edit mode if the TextBox loses focus):
public class SelectAllTextOnGotFocus : Behavior<TextBox>{ protected override void OnAttached() { base.OnAttached(); AssociatedObject.GotKeyboardFocus += AssociatedObjectGotKeyboardFocus; AssociatedObject.LostKeyboardFocus += AssociatedObject_LostKeyboardFocus; } protected override void OnDetaching() { base.OnDetaching(); AssociatedObject.GotKeyboardFocus -= AssociatedObjectGotKeyboardFocus; AssociatedObject.LostKeyboardFocus -= AssociatedObject_LostKeyboardFocus; } private void AssociatedObjectGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { AssociatedObject.SelectAll(); } private void AssociatedObject_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { DependencyObject d = VisualTreeHelper.GetParent(AssociatedObject); while (d != null) { if (d is XamDataTree) { (d as XamDataTree).ExitEditMode(false); break; } d = VisualTreeHelper.GetParent(d); } }}
It can be attached via the EditorTemplate property of a NodeLayout:
<ig:NodeLayout.EditorTemplate> <DataTemplate> <TextBox Text="{Binding Path=Data.Label, Mode=TwoWay, UpdateSourceTrigger=Explicit}"> <i:Interaction.Behaviors> <local:SelectAllTextOnGotFocus /> </i:Interaction.Behaviors> </TextBox> </DataTemplate></ig:NodeLayout.EditorTemplate>
Hi Gergana,
Thanks s lot. I totally missed the ExitEditMode() method. That solves my problem.
The other issue is not really an issue because everything works as it should, I just thought I'd report the error message that I am getting.
I have been looking into your post. For your first requirement, when you press the ALT+Tab keys I can suggest to handle the StateChanged event of the Window, that contains the xamDataTree. In the event handler of this event you can check if the window goes in minimized mode and if the ALT+Tab keys are pressed, to make the xamDataTree exit edit mode. Using the following line the xamDataTree, should exit edit mode: this.SampleTree.ExitEditMode(true);
For your second requirement about the binding error I have logged this behavior with our developers in our tracking system, with an issue ID of 146465. I have also created a support ticket on your behalf with number CAS-119482-S6B7K0 in order to link the development issue to it so that you are automatically updated when a Service Release containing your fix is available for download.
Please do not hesitate to let me know if you have any further questions on the matter.
thanks for your answer.
OK, then I have this question:Can I somehow exit edit mode programmatically?Because I have an application that uses the XamDockManager, and the current behavior of the XamDataTree is that- clicking anywhere in the main window exits edit mode, but- clicking into a floating window within the same application does not exit edit mode.
This feels inconsistent.
For the binding error I have attached a VS solution that demonstrates it.Run in debug mode and watch the output window when hitting F2 to edit a node.
After that, comment the ItemTemplate and do the same again: the error no longer appears.
Since I need to use an ItemTemplate, I was wondering if it was a mistake on my side.