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

Focus Events Issue

11 Answers 628 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Chris Anderson
Top achievements
Rank 1
Chris Anderson asked on 13 Sep 2012, 03:19 AM
The focus events for the RadRichTextBox don't appear to be firing correctly.  There's a number of issues, which I'll list in turn.  We need to do things according to whether the control has the focus or not, and currently its unexpected behaviour is causing us a lot of problems.

For the purpose of reproducing the behaviour, simply place a RadRichTextBox control on a view, and handle its GotFocus and LostFocus events with the following event handlers, which will write to Visual Studio's Output window so you can see that they've been called.

private void RadRichTextBoxEx_LostFocus(object sender, RoutedEventArgs e)
{
    Console.WriteLine("LostFocus");
}
 
private void RadRichTextBoxEx_GotFocus(object sender, RoutedEventArgs e)
{
    Console.WriteLine("GotFocus");
}


#1 - Clicking the mouse anywhere within the control fires the events

Let's say the RadRichTextbox control has the focus.  Clicking the mouse anywhere within the control fires the LostFocus and GotFocus events twice, with the following output in the VS Output window:

LostFocus
GotFocus
LostFocus
GotFocus

I would expect neither the LostFocus not the GotFocus events to be fired, as the control already has the focus.

If the control doesn't have the focus and you click in it (giving it the focus), then the following events are currently raised:

GotFocus
LostFocus
GotFocus

In this situation, I would expect only the first GotFocus event to be raised.

NOTE: I have tried handling the KeyboardGotFocus/KeyboardLostFocus events, and they behave the same way.

#2 - Clicking on a control that doesn't take focus, still fires these events

Let's say the RadRichTextBox control has the focus, and you click on a different control that doesn't steal the focus from the RadRichTextBox control, such as a ribbon button (note, we aren't using the Telerik ribbon currently, but that shouldn't matter).  Doing so fires the events like so:

LostFocus
GotFocus

The expected behaviour is that neither of those events should be called.

#3 - When overriding the RadRichTextBox control, neither the OnGotFocus, nor the OnLostFocus methods fire

While this is not really an issue for me, I tried overriding the RadRichTextBox control to add my own behaviour to it, and found that if I override the OnGotFocus and OnLostFocus methods, they never get called.  Something maybe to look at as part of this problem.

Please note that all these scenarios have been tried on a plan TextBox control, and it fires its GotFocus/LostFocus events as per my expected behaviour described.  Therefore, I would expect the RadRichTextBox control to behave in the same manner.

Thanks

Chris Anderson

11 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 14 Sep 2012, 02:59 PM
Hi Chris,

Thank you for contacting us about this issue.

RadRichTextBox is a quite complex control and uses different UIElements in order to show its content and provide the option to edit the document. For example, in order to show a caret and have it blink when you edit in the document, we use a TextBox. However, this TextBox gets the focus when you click in the editor and returns it to the RadRichTextBox following some internal logic. This causes the GotFocus and LostFocus events to be fired, even though it is not normally expected.

As for the ribbon buttons, they do steal the focus from the editor. The rich text box receives the focus back after they are pressed, because the commands that the ribbon buttons execute force the focus back to the editor.

Can you provide some more details on the goal you wish to achieve?

All the best,
Iva Toteva
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Chris Anderson
Top achievements
Rank 1
answered on 21 Sep 2012, 07:46 AM
Thanks for your reply Iva.  We have put some "hacky" workarounds for this existing LostFocus/GotFocus behaviour, but it would still be good to have it fixed.  The control should only fire the GotFocus event when it receives the focus, and only fire the LostFocus event when it has lost the focus, regardless of the internal implementation of the control itself.  Clicking to move the cursor within the rich text box should definitely not fire the LostFocus event as per point #1 from my original post.

From my tests, the ribbon buttons do not steal the focus from controls.  I put a standard text box on a view with a ribbon, and handled its LostFocus event.  It only ever gets called when the focus has moved away from the text box.  It is not fired when the ribbon buttons are clicked.  Therefore I would expect the RadRichTextBox control to behave in the same manner.

Thanks

Chris Anderson
0
Iva Toteva
Telerik team
answered on 26 Sep 2012, 05:31 PM
Hi Chris,

Thank you for the follow-up. It is good to hear that you have found a solution to get it working in your project.

We will log the issue for revision and will try to fix it for one of the future releases.

Kind regards,
Iva Toteva
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Chris Anderson
Top achievements
Rank 1
answered on 27 Sep 2012, 12:12 AM
OK, thanks Iva.

Chris
0
Artem
Top achievements
Rank 1
answered on 21 Nov 2017, 04:42 PM
Well, it is 2017. The problem is still reproducable. Seems like the issue is still in progress or maybe skipped as it often happens
0
Boby
Telerik team
answered on 22 Nov 2017, 02:11 PM
Hello Artem,

The confusing raising of events is still not fixed. Big part of the internal UI infrastructure relies on the current implementation, which makes the issue relatively complex. I just created a public item for the internal bug:
RichTextBox: Focus events are not raised consistently
which you can use to track an eventual progress on the matter.

Regards,
Boby
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Artem
Top achievements
Rank 1
answered on 23 Nov 2017, 12:01 PM
Well, actually looking through the progress from 2012 to 2017 - nothing changed with this problem. Do you really think, that setting it as a bug will force it solving. I only think, that in a few years this bug will be moved to Won't fix state.
0
Boby
Telerik team
answered on 24 Nov 2017, 09:25 AM
Hello Artem,

The public portal was not present at the time the thread was started, so the bug was logged internally, and I just exposed it publicly. Otherwise, we carefully prioritize the backlog using different tactics, trying to fix the most pressing problems first. The status of the bug is currently not Won't Fix, meaning that we consider it for fixing and re-prioritize it at least quarterly. As of now though, the bug is not scheduled for specific release, so I cannot commit to specific time frame for its fixing.

Could you share what is your exact scenario, we may be able to find a workaround for the issue that suits it?

Regards,
Boby
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Bruce
Top achievements
Rank 2
answered on 11 Dec 2018, 09:07 PM

We are having a similar issue with focus not coming back to the radRichTextBox after clicking on a button on the radToolBar (ribbon). We're currently on the February 2017 release of the WPF Telerik controls. Is there any update on this? 

0
Bruce
Top achievements
Rank 2
answered on 11 Dec 2018, 10:06 PM
I neglected to mention that our situation is that the control is in a popup window. It looks like the functionality works properly when not in a popup.We cannot even find a way to hack the focus to get the cursor back after clicking one of the ribbon buttons.
0
Boby
Telerik team
answered on 14 Dec 2018, 03:59 PM
Hello Bruce,

The issue seem similar to this one: RichTextBox: Focus is not returned to the caret when the Font Family or Font Size combo boxes are used and the LayoutMode is Flow, which was a regression introduced in R1 2017, and fixed in R2 2017 SP1.
 
Could try the workaround described in the item? If the problem is not this one, or you have further questions on how to adapt the workaround for your case, please open a separate support ticket, as this thread is around another focus-related peculiarity of the control.

Regards,
Boby
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
Chris Anderson
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Chris Anderson
Top achievements
Rank 1
Artem
Top achievements
Rank 1
Boby
Telerik team
Bruce
Top achievements
Rank 2
Share this question
or