This is a migrated thread and some comments may be shown as answers.

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

2 Answers 31 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 08 Jul 2016, 03:47 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 13 Jul 2016, 12:31 PM
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.
0
Thomas
Top achievements
Rank 1
answered on 18 Jul 2016, 09:50 PM

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.

 

Tags
Diagram
Asked by
Thomas
Top achievements
Rank 1
Answers by
Martin
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or