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

LostFocus event

3 Answers 520 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 15 Jun 2015, 07:22 AM

Hello,

I've currently writing a control that descends from RadRichTextBox, with an additional HtmlText dependency property, so that I can  directly bind an HTML content to the RichTextBox. To avoid performances issues, the HtmlText dependency property should be updated only when the RichTextBox loses its focus.

First problem: The OnLostFocus virtual method is never called when the control loses its focus. This is contrary to the WPF guidelines: if an On<EventName> virtual method is defined it should be called to raise the event, so that descendant classes can override this method instead of adding an event handler. This has the advantage that we are sure that the control is notified before the event listeners and can act accordingly.

Second problem: The LostFocus event is called repeatidly: justr clicking on the control, when it doesn't have the focus raises it twice.

3 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 17 Jun 2015, 04:53 PM
Hello Partick,

The behavior of the LostFocus event is known and the reason behind it is that the caret in the RadRichTextBox is implemented using a TextBox. When you click in the editor, the focus is passed to the caret and that is why this event is raised (it is raised several times because this is a routed event). I'm afraid there isn't much you can do about this as it is a design issue.

The issue with the OnLostFocus() method is related to the one mentioned above - the focus is in the caret and when it is lost, the event is not raised from RadRichTextBox raised but from the caret. However, we think that the implementation of this logic could be improved and logged a task for it in our backlog.

I am afraid that I am not able to give you a workaround at the moment and would suggest triggering the update logic with another approach.

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 22 Jun 2015, 09:33 AM
Hi Tanya

[quote]Tanya said:the focus is in the caret[/quote]

Perhaps this explains some other problems with the focus:

1. Setting the focus by code doesn't seem to work.
2. I have the ribbon that is showing the main edition part only when the focus is on a RichTextBox, and it disappears when I click a button on the ribbon that is not related to the RichTextBox.

0
Boby
Telerik team
answered on 25 Jun 2015, 06:10 AM
Hi Patrick,

Invoking RadRichTextBox.Focus method actually transfers the focus directly to the internal TextBox. I guess this is what you mean by "1. Setting the focus by code doesn't seem to work" - yes, the actual focused element is not RadRichTextBox anymore.

For 2., the default Ribbon UI is bound to RadRichTextBox using RichTextBoxCommands, most of which internally invoke RadRichTextBox.Focus after executing the main action. This is to ensure that the focus is immediately returned the editor, where the used can continue typing/executing commands.

If you have specific problem implementing the desired scenario, you can open a support ticket and upload a sample solution demonstrating it - we may be able to suggest you a solution.

Regards,
Boby
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Tanya
Telerik team
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Boby
Telerik team
Share this question
or