RibbonButton remaining highlighted after click

Apr 5, 2013 at 1:25 PM
Edited Apr 5, 2013 at 1:25 PM
I know this has been mentioned before on the CodeProject discussion thread, but the fix referenced there (which points to 19578) for RibbonButtons remaining highlighted after a click (that opens another window) does not appear to work for Win7/Aero.

There appears to be four cases for this behaviour which can be seen by creating a button on a RibbonPanel and by showing another dialog when clicked (in my case, I simply open a SaveFileDialog). The four cases are:
  1. Click the button, do not move mouse, and wait for the dialog to open. Close the resulting window with a keyboard shortcut. When the dialog closes, the button should remain highlighted (because the mouse remains over it after the window closure). In my tests, this works properly.
  2. Click the button, do not move mouse, and wait for the dialog to open. Move the mouse away from where the button would be and close the dialog. When the dialog closes, the button should not remain highlighted (because the mouse is no longer over it). In my tests, this does not work as intended -- the button (and panel) remain highlighted.
  3. Click the button, but quickly move the mouse off the button prior to the dialog opening. Close the dialog. When the dialog closes, the button should not remain highlighted (because the mouse is no longer over it). In my tests, this works as intended.
  4. Click the button, but quickly move the mouse off the button prior to the dialog opening. Close the dialog. When the dialog closes, the button should be highlighted (because the mouse is over it). In my tests, this works as intended.
What the failed test cases indicates to me is that the ribbon isn't receiving a message that the mouse has left the button when another window has focus (to be expected). However, when the window closes and focus returns to the calling form, could a mouse check not be performed then? Unfortunately I'm not familiar enough with this project's architecture to attempt a solution.

Love the project!
Developer
Apr 9, 2013 at 4:38 PM
As far as I understand you only case 2 is not working on your side. I did my tests on both XP and Win7 and as far as I can remember it worked for your case 2.
The implementation is that the highlighting is cleared before the dialog is opened (so I would understand if your case 1 is not working).
Check RibbonItem.cs:
public virtual void OnClick(EventArgs e)
{
    if (!Enabled) return;

    if (ClosesDropDownAt(Canvas.PointToClient(Cursor.Position)))
        RibbonPopupManager.Dismiss(RibbonPopupManager.DismissReason.ItemClicked);

    SetSelected(false);  // this removes the highlighting

    if (Click != null)
    {
        Click(this, e);
    }
}