Focus Events Issue

5 posts, 0 answers
  1. Chris Anderson
    Chris Anderson avatar
    6 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post

    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
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 14 Sep 2012 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris Anderson
    Chris Anderson avatar
    6 posts
    Member since:
    Sep 2012

    Posted 21 Sep 2012 Link to this post

    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
  5. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 26 Sep 2012 Link to this post

    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.

  6. Chris Anderson
    Chris Anderson avatar
    6 posts
    Member since:
    Sep 2012

    Posted 26 Sep 2012 Link to this post

    OK, thanks Iva.

    Chris
Back to Top
UI for WPF is Visual Studio 2017 Ready