I would like to be able to have my ribbon permanently minimized, then `expand` on mouse enter and `collapse` again on mouse leave.
The only events on the ToolbarManager I can see that might be useful is MouseEnterElement and MouseLeaveElement and in there set the
.minimized property of the ribbon. Even in those events the ribbon would minimize when going from one tool to another on the ribbon, I would then also need a way to check if the mouse is still over the ribbon or a toolbar to prevent `flashing`.
As far as I can tell though, these events only fire when the mouse enters or leaves a control on the ribbon, like a button or dropdown menu.
The events would then be skipped completely should the mouse wander over empty ribbon tab space or toolbar space.
Please advise if there is an easier way to accomplish this. Thanks in advance
The MouseEnterElement and MouseLeaveElement event fire whenever the mouse moves to new UIElements. If you are over a big empty space, chances are it is displayed by a single UIElement and therfore the events shouldn't fire. However, I think I was able to imlement this. Try using the following code and let me know if this is what you are looking for (don't forget to hook up the event handlers for MouseEnterEement and MouseLeaveElement):
public Form1(){ InitializeComponent();
this.ultraToolbarsManager1.Ribbon.IsMinimized = true;}
private void ultraToolbarsManager1_MouseEnterElement( object sender, UIElementEventArgs e ){ this.ultraToolbarsManager1.Ribbon.IsMinimized = this.ShouldMinimizeRibbon( e.Element );}
private void ultraToolbarsManager1_MouseLeaveElement( object sender, UIElementEventArgs e ){ // When leaving elements, we only want to collapse the ribbon in some case. //If it is already collapsed, we don't have to do anything. if ( this.ultraToolbarsManager1.Ribbon.IsMinimized ) return;
Point screenPoint = Cursor.Position; Point formClientPoint = this.PointToClient( screenPoint ); Control controlAtPoint = this.GetChildAtPoint( formClientPoint, GetChildAtPointSkip.Invisible );
UltraToolbarsDockArea dockArea = controlAtPoint as UltraToolbarsDockArea;
// If the mouse is not over a dock area, immediately collapse the ribbon and return. if ( dockArea == null ) { this.ultraToolbarsManager1.Ribbon.IsMinimized = true; return; }
UIElement mainElement = ( (IUltraControlElement)dockArea ).MainUIElement; Point dockAreaClientPoint = dockArea.PointToClient( screenPoint );
if ( mainElement != null ) { UIElement childElement = mainElement.ElementFromPoint( dockAreaClientPoint );
// If the ribbon should be collapsed based on the current element the mouse is over, collapse it. if ( this.ShouldMinimizeRibbon( childElement ) ) this.ultraToolbarsManager1.Ribbon.IsMinimized = true; }}
private bool ShouldMinimizeRibbon( UIElement mouseOverElement ){ // When the mouse goes over the tab line element, the minimized state should not change if ( mouseOverElement is TabLineUIElement ) return this.ultraToolbarsManager1.Ribbon.IsMinimized;
// Show the ribbon tabs if the mouse goes over a ribbon tab item or an element on a ribbon tab page return mouseOverElement.GetAncestor( typeof( RibbonTabItemUIElement ) ) == null && mouseOverElement.GetAncestor( typeof( RibbonTabPageUIElement ) ) == null;}
Hi Mike
Thanks for the reply. It works well. The only issue I have it that it seems a bit "jumpy".
Is it possible for me to drop down the tab the mouse has entered only (as it happens when you click on a tab when the ribbon is collapsed), instead of changing the minimization of the whole ribbon?
Thanks in advance
Sure, the Ribbon has a DropDown method which will show the tab drop down for the currently selected tab. However, you will probably want to change the currently selected tab before dropping down the ribbon. You can do this by just handling the MouseEnterElement event with the following code:
RibbonTabItemUIElement tabElement = e.Element as RibbonTabItemUIElement;
if ( tabElement == null ) return;
RibbonTab tab = tabElement.TabItem as RibbonTab;
if ( tab == null ) return;
tab.Ribbon.SelectedTab = tab;tab.Ribbon.DropDown();
Works very well, thanks Mike.
One more issue though. The ribbon now drops down, but when the mouse
leaves the menu it does not collapse until the user clicks on another element on the form that's not on the ribbon. I cannot seem to find a corresponding "collapse" method for the ribbon as well?
Please advise. Thanks.
Nevermind. I see that calling .DropDown() basically toggles the drop down of the tab. Thanks
Another question thgough. Is there a way to verify whether the ribbon is in a drop down position or not?
I don't believe that is exposed. You can submit a feature request for this: http://devcenter.infragistics.com/Protected/RequestFeature.aspx.
Also, I probably should have mentioned this earlier, but this technically violates the Office 2007 UI Guidelines. They state that you should not expand the ribbon based on the mouse hovering over a tab and it states that it must remain open regardless of mouse position, so it should not close up when the mouse leaves the tab page. Also, the guidelines state that the ribbon should not be minimized the first time the application is run. It should only be minimized if the user minimizes it.