I'm try to get each ribbon tab on child form when its loaded to set the first tab (index 0) so the user would see this tab as the selected tab.
I read the following blog and tried it in VB.net:
>>> Ultratoolbarsmanager: How to programmatically activating a child tab
Here's my code:
==========================================================================
If Not activeChildManager Is Nothing Then
Dim parentTab As RibbonTab = childTab.AttachedParentTab
If Not parentTab Is Nothing Then
Else
End If
========================================================
But, [activeChildManager] is "Nothing" when I run the code
Note: the above code is located in the parent MDI form "MdiChildActivate" event.
Is the the correct location? (this is where I would like to manage all forms that load)
Have we missed something?
Thanks ahead of time.
Patrick
This is not the recommended location to sync up after an mdi child has been merged. The problem is, hooking this event is the only way the toolbars manager can determine when to merge with the newly active child, and if the toolbars manager happens to hook the event after your code does, your event handler of MdiChildActivate will likely get called before the toolbars manager's event handler. You would be called before the merge, and it looks like that's what's happening here.
It is instead recommended that you override OnMdiChildActivate in the parent form. Your implementation should call the base implementation first (this will call all event handlers, including the one on the toolbars manager which performs the merge), then it should select the first child tab.
Thanks Mike, but I could use more data. Where should I try this?
Any examples I could look at?
Thanks again,
Well Chris, I pulled down your sample and copied over my exact toolbar setups and was not able to reproduce. I've clearly got something happening somewhere else in the code. I'll keep poking at it. Thanks for your help.
Hi Matt,
If you narrow down the cause of the issue with your application, please let me know. Hopefully we can add a fix for this scenario within our controls to avoid this issue in the future.
Additionally, if you have any other questions, feel free to ask.
Thanks,
Chris
Thanks Chris. I have some stuff happening in the AfterRibbonTabSelected event - when I comment that out, I do not experience the issue. (Of course, then the application doesn't function as expected). When I figure it out, I will come back and post.
OK. I brought in some code very similar to what we are using in the app and I was able to replicate the exception. In fact, it happens immediately upon starting the application. I'm still clueless as to what is actually causing this, but I found that if certain bits are commented out, the exception does not arise. I believe it is somehow related to the fact that the Home tab (the first tab on the parent ribbon) is always selected before the tab hosting the child tab is selected.
I've notated the attachment. I upgraded this project to 2014.2 FYI.
Please let me know what you are able to discover.
Thanks Matt. I was able to reproduce the issue with the sample you provided. It appears that the code is causing a recursion issue where the OnMdiChildActivated() method is changing the SelectedTab, and then the AfterRibbonTabSelected event handler is activating a different child form. This causes the UltraToolbarsManager to step over itself as it recursively unmerges/merges the different ribbons.
Adding recursion flag seems to work in my sample. Just replaces the OnMdiChildActivate() override and AfterRibbonTabSelected event handlers with the following code:
Dim flag As Boolean
Protected Overrides Sub OnMdiChildActivate(e As EventArgs) MyBase.OnMdiChildActivate(e) 'Exception comes here
If Me.flag Then Return End If
If Me.tbrMain.ActiveMdiChildManager IsNot Nothing Then Me.tbrMain.Ribbon.SelectedTab = Me.tbrMain.ActiveMdiChildManager.Ribbon.Tabs(0).AttachedParentTab End If
End Sub
Private Sub tbrMain_AfterRibbonTabSelected(sender As Object, e As Infragistics.Win.UltraWinToolbars.RibbonTabEventArgs) Handles tbrMain.AfterRibbonTabSelected
Dim original As Boolean = Me.flag Try Me.flag = True Me.FiddleWithActiveWindowsBasedOnTabSelection(e.Tab) Catch ex As Exception Me.flag = original End Try End Sub
Let me know if this works for you.
Thanks for everything Chris. Your help is a testament to the level of customer care that we've come to expect from Infragistics.
~Matt
Hey Matt.
I am the primary engineer for our toolbars suite, so of course I'll look deeper into the issue with the SelectedTab being different than the tab provided within the EventArgs.
In regards to the FontSize question, normally, we restrict the font size for all tools to be the same within the same parent. However, for the Ribbon, a single font size is enforced across the entire Ribbon. All tool/RibbonGroup related FontSize properties will be ignored. You would have to change the Ribbon's GroupSettings.ToolAppearance.FontData.FontSize for it to take affect. However, this will affect all tools on the Ribbon. If you are looking to only change the FontSize for this one tool, you'll most likely have to switch from using a TextBoxTool to using a ControlContainerTool and assigning an UltraTextEditor as the Control.
I hope this helps.
Thanks Chris, you've been a tremendous help. Not to be greedy with your time, but while I've got you, a couple of things:
1) By way of completeness, I wanted you to see that the toolbar's selected tab and the tab that is sent in AfterRibbonTabSelected are different any time the selected tab is changed in code. This is evidenced in the attached sample project. Might want to have an engineer look that over.
2) How ON EARTH do I get the font size to change on a TextBoxTool on the ribbon? On the Search tab in the attached project, I've got a text box tool that I am dying to have Comic Sans at 24 points. The InstanceProperties.EditAppearance seems to have allowed me to modify the font family, but not the size. Help?
Glad to hear that you got it working. I'm guessing it is the recursion that causes the ribbon's SelectedTab to be changed again after it fires the AfterRibbonTabSelected for the e.Tab.
Let me know if you need and further assistance.
Hey Chris, I was able to get this sorted. Definitely some oddness here because in the AfterRibbonTabSelected event, the ToolbarsManager.Ribbon.SelectedTab is NOT THE SAME as e.Tab. Anyway, managed to get around this using the below code.
Private Sub tbrMain_AfterRibbonTabSelected(sender As Object, e As Infragistics.Win.UltraWinToolbars.RibbonTabEventArgs) Handles tbrMain.AfterRibbonTabSelected If Not (e.Tab.Key.ToUpper.Contains("HOME") And (Me.tbrMain.Ribbon.SelectedTab IsNot Nothing AndAlso Me.tbrMain.Ribbon.SelectedTab.Key.ToUpper.Contains("MDICHILD"))) Then Me.FiddleWithActiveWindowsBasedOnTabSelection(e.Tab) End If End Sub