Accessing Ribbon Controls Programatically in an XML Ribbon - c#-4.0

For programming Office Add-ins using C# 4.0, Microsoft provides two different ways of creating and/or modifying the Ribbon interface: you can use the Ribbon Designer or define the Ribbon's layout in Ribbon XML.
If you create a ribbon using the Ribbon designer, the class generated in the code behind has visibility to all the controls you've placed on the ribbon. So if I've placed a RibbonDropDown called "dropdown1", I could use the following code to add an item to it:
RibbonDropDownItem item = Factory.CreateRibbonDropDownItem();
item.Label = submatrix.Name;
item.Tag = submatrix;
this.dropDown1.Items.Add(item);
However, if you create the same Ribbon using Ribbon XML, dropDown1 or Factory aren't found ("The name does not exist in the current context").
Is there a way to access the items added to a Ribbon XML-defined ribbon in code?

Might be a little late, but hopefully this helps someone.
I was utterly confused about this same issue. Turns out, you can only access these controls as string ids, and the model is heavy on invalidation events. So for example, when you get a button click via onAction method, you only have the sender's id from the control object, however, in this event handler, you can invalidate the other controls and have their events called using
ribbon.InvalidateControl("MyCtl");
check out this MS Lab, it has everything you need to get up and running

Related

Show or Hide a VSTO Addin Ribbon

My goal is to simply offer my addin if Office application is launched with a certain argument.
Unfortunately, I could not find anything to help me do this. I have tried to use the Office Application Load Addin swtich /lc:Addin.dll with no success. One option I entertained was to create all of the Office addin registry entries upon time of wish to launch addin however this seemed extremely clumsy and way to much overhead. Also, the deal breaker for me was requiring registry creation elevated privileges in order to initialize the addin.
I decided to have my addin not do much of anything at startup unless a certain environment variable exists.
In order to do it this way I need to either set the ribbon to non-visible by default and show the Ribbon upon discovering the env variable. Or the opposite have the ribbon visible by default and hide the ribbon upon discovering env variable.
Things I have tried
Setting ribbon's tab Globals.Ribbons.MyRibbon.MyTab.visible = false.
Invalidating the Ribbon Globals.Ribbons.MyRibbon.RibbbonUi.Invalidate().
Invalidating the tab after setting visible to false Globals.Ribbons.MyRibbon.RibbbonUi.InvalidateControl(tabCtrlId).
The things tried dont include the dozens of thing to try to only load addin in certain circumstances.
I figured out a solution.
after digging into the base class AddinBase I discovered some methods available for me to override.
So I overrode the CreateRibbonExtensibilityObject method.
protected override IRibbonExtensibility CreateRibbonExtensibilityObject( )
{
if( Environment.GetCommandLineArgs( ).ToList( ).FirstOrDefault( a => a.ToLower( ).Contains( "/launchmyaddin" ) ) != null )
{
return null;
}
return base.CreateRibbonExtensibilityObject( );
}
What this does is prevent the ribbon from even being created if my switch is present and if it is present then I just pass off to the base class implementation in order to have the Addin create my ribbon like normal.
Also, CreateRibbonExtensibilityObject() returns an object that has a GetCustomUI( ribbonXml ) so we can create our custom ribbon from xml.
This gives us more power.
My solution only needed to show/hide a ribbon once only at startup. I did think about how this might be toggled on and off so I went poking around for other members I could override.
I believe you can override the CreateRibbonObjects( ) member which I think will get called upon every time the invalidate of a ribbon is called. Here you may be able to remove the item from the collection the base class returns that represents your ribbon you wish to hide.
If you use custom tab(s) (this is, ControlIdType=Custom) you may set visibility via:
foreach (var tab in Globals.Ribbons.Ribbon1.Tabs)
{
tab.Visible = false;
}

How to Get a pointer to MFC Ribbon ComboBox

I'm developing an MFC Ribbon application on visual studio 2013 and I'm new in MFC developement.
I've added MFC Ribbon ComboBox from designer window. Now, I want to add data runtime into MFC Ribbon ComboBox, I've done google & read MSDN as well as Code Project example regarding MFC Ribbon. but, I was unable to figured how to get pointer to combobox and add data into it.
You can use CMFCRibbonBar::FindByID. So, something like this:
CMFCRibbonComboBox *pCombo = DYNAMIC_DOWNCAST(CMFCRibbonComboBox,
m_wndRibbonBar.FindByID(ID_COMBO1));
The ID you use (in the above example ID_COMBO1) is the ID you gave it in the Properties window in the ribbon designer, and m_wndRibbonBar is the member variable of the ribbon itself, which is usually auto-generated in your CMainFrm class.

Creating a ribbon custom button when inserting content to Sharepoing 2010

I want to create a button to popup a window and display a list that it's being requested to an external source. Then the user would click on one of the items to insert and iframe on the body of the post.
For this I think best way is to create a ribbon custom button right? How can I make it only appear when inserting content such as posts?
You need to create a custom action in your project. It's a small xml file that gets installed in the farm and dislays what ever you want. Check How to add a ribbon item using CustomAction in sharepoint 2010? for a sample and here for extended information on all the possibilities you have http://msdn.microsoft.com/en-us/library/bb802730.aspx

Excel VBA - Intercept AddIn Ribbon Click

i would like to know if it is possible to intercept the event generated by the Ribbon Button of an Excel Addin. I'm able to access to the .xlam source but seems there is no code in it that intercept that event, so I think the handler is in the compiled component. Is my assessment correct? And then, if yes, can I intercept a click on a button of the ribbon, maybe using an Application Level Handler?
Thank you,
DD
The Ribbon button has a callback assigned to its onAction attribute - it will be a Sub in the addin that has an iribboncontrol parameter (or similar). If you have can view the customui part of the add-in's XML you will be able to determine exactly which callback is relevant.

Winforms c# outlook like Interface

I have already asked the same question but in regards with MDI Application design. Now just for R&D purpose so that we can go with 2 solutions to our user. Can somebody plz help me out...
We are developing an OutLook Style Application using C# Winforms. In that application we are using Microsoft Table Control. Which is what we need to show our UI. In the left hand pane we have menu and in the right hand we are displaying our UserControl. Like CustomerManager. This UserControl is doing Adding, Updating, Deleting ect etc but we want to put the common action buttons, Like Add,Delete,Save on the top toolbar.
So far so good, Now what we need to acheve is regardless of UserControl. What ever UserControl is loaded in the MainForm's TableControl. When the save button is clicked it should process the data on that UserControl. Obviously we will write the logic of the Save Action on each UserControl.
Please help...
Regards
Shanx
I may advice you the Krypton Toolkit. You will write an Outlook style app in seconds.
For all who ended up here like me in search of a free toolkit: As Vulkanino suggested to use Krypton, I loooked it up.
This is now open source Freeware and can be found unter: Krypton Toolkit
Create a Base user control that contains your Add, Delete, Save methods and events. Then create every other functional control that inherits from the Base control.
When you action the main toolbar buttons, you can safely cast each user control in your given container, to the Base user control.
Some MSDN links you might want to read up on:
http://msdn.microsoft.com/en-us/library/44a9ty12(VS.80).aspx
http://msdn.microsoft.com/en-us/library/ms173149(VS.80).aspx

Resources