How to select a diagram object without setting the focus on the user control

3 posts, 1 answers
  1. Thomas
    Thomas avatar
    4 posts
    Member since:
    Apr 2016

    Posted 08 Jul Link to this post

    Hello Telerik community,

    First post for me here :)

    I would like my diagram (placed in a userControl) to react to some events in my MDI application. (events done in other usercontrol, like clicking on a portion of a text would select the text-corresponding box in the diagram)

    The problem I have is that when I set my:

    //(Telerik.Windows.Controls.Diagrams.Extensions.ViewModels.ItemViewModelBase NodeViewModel;)
    NodeViewModel.IsSelected = true;

    My diagram userControl gets the focus and the user can't type text anymore.

    I would like to be able to change the selected item in my diagram without changing the application focus.

    Any idea to achieve that? 

    Thanks a lot!

    - Thomas

  2. Answer
    Martin
    Admin
    Martin avatar
    60 posts

    Posted 13 Jul Link to this post

    Hi Thomas,

    When you are setting IsSelected=true to the RadDiagramShape, the diagram focuses the shape internally in code.

    If I understand you correctly, you would like to keep the focus on the TextBox while the user is writing, but select the matched item.

    Easiest thing would be to manually set the focus back to the TextBox after you set IsSelected to the shape. This would put the cursor at the end of the text already in the Textbox, so the user could continue to write.

    NodeViewModel.IsSelected = true;
    if (!textBox.IsFocused)
      {
        textBox.Focus();
      }
    If that does not satisfy your requirement or if I had misunderstood your case, could I ask you to provide more information and/or runnable code snippets/project.

    Regards,
    Martin
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Thomas
    Thomas avatar
    4 posts
    Member since:
    Apr 2016

    Posted 18 Jul in reply to Martin Link to this post

    Thank you for your answer.

    I've followed your advice and used the Keyboard class to support the feature: 

    IInputElement focusedElement = Keyboard.FocusedElement;

    // ... setting viewModel.IsSelected = true where it needs to be done

    Keyboard.Focus(focusedElement);

    Works perfectly.

     

Back to Top