Treeview item with child noes swallows ENTER

2 posts, 0 answers
  1. Mark
    Mark avatar
    50 posts
    Member since:
    Dec 2010

    Posted 02 Apr 2013 Link to this post

    I have a treeview with a HierarchicalDataTemplate containing a user control that has a textbox. the textbox has AcceptReturn=true.

    If the treeview item has a child node then the treeview does not pass the enter to the UC.

    I have this handling the keydown event on the treeview.

    private void EnterDown(object sender, KeyEventArgs e)
        if (e.Key == Key.Enter)
            e.Handled = false;

    How do I pass the enter key down to the textbox in the user control in all cases
  2. Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1167 posts

    Posted 05 Apr 2013 Link to this post

    Hello Mark,

    Unfortunately, it seems that there are differences in the functionality of the TextBox control in Silverlight and WPF. In order to enter a new line in the TextBox (when it is nested in a RadTreeViewItem) in SL, you can press Shift+Enter.

    Another way to achieve your goal (which we implemented in the attached project) is to subscribe to the PreviewExpanded and PreviewCollapsed events and check if the focused element is TextBox. If so you can handle the events and the respective RadTreeViewItem will not expand while the TextBox will add a new row into its content. Please note that we also handle the KeyDown event of the TextBox control. By doing this, if you want to expand the RadTreeViewItem using the Enter key you will have to focus the item

    Please take a look at the attached project and let us know if it works for you.

    Pavel R. Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top