LostFocus event

4 posts, 0 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 15 Jun 2015 Link to this post

    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.

  2. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 17 Jun 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 22 Jun 2015 in reply to Tanya Link to this post

    Hi Tanya

    Tanya said:the focus is in the caret

    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.

  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 25 Jun 2015 Link to this post

    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
Back to Top