none
Invalidate control on XML Ribbon RRS feed

  • Question

  • I have an XML Ribbon with a synchronise button on it. If the synchronise method is in progress a boolean (synchronising) is set to true. When synchronisation is complete this property is set back to false.

    I want to be able to change the image of the button, or disable the button, in the code when i change this property.

    How can i do this? I assume an invalidate on the button would work but i don't have an IRibbonUI being passed in to my ribbon's load event (It comes in as null, i assume this is because i am using the XML ribbon?).


    http://endgameinteractive.co.uk
    Wednesday, January 18, 2012 1:16 PM

Answers

  • comment out this override and try to use following method:

    protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(IRibbonExtensibility).GUID)
                {
                    return new Ribbons(Application);
                }
                return base.RequestService(serviceGuid);
            }
    

     

    Of course you do not need to store Application object in your ribbon if you do not need to. Is ribbonUI passed when you use this initialisation routine?

     

    • Marked as answer by Kev Pearman Thursday, January 19, 2012 8:39 AM
    Wednesday, January 18, 2012 3:47 PM

All replies

  • normally you would do this by setting in ribbon xml functions for determining state of control, sample:

    getVisible ="YourGetControlVisibleState"

    and then call ribbonUi.InvalidateControl(controlId)

     

    but of course you need ribbonUI to be not null, so try to determine why you get it as null.

    Wednesday, January 18, 2012 1:35 PM
  • RibbonLoad(IRibbonUI ribbonUI) is called by outlook, not by any code in my project. Not much i can do to diagnose why it's coming in as null if i can't get at the method call.

    Anyone got any suggestions?


    http://endgameinteractive.co.uk
    Wednesday, January 18, 2012 3:09 PM
  • just to make sure: you are starting your outlook normally and your OnLoad function is called with ribbonUI being null? please paste here code you use to register your ribbon object in outlook. Or maybe you are starting outlook in different way (for example - send to in windows shell)?
    Wednesday, January 18, 2012 3:16 PM
  • my RibbonLoad method

    public void RibbonLoad(IRibbonUI ribbonUI)
    {
        _ribbon = ribbonUI;
    }

    my ribbon initialise code in the addin

    protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
        _ourRibbon = new OurRibbon();
        return _ourRibbon;
    }

    Is this everything you wanted to see?

     

    I am starting the add in by running the project in visual studio, or by just opening outlook once it's been installed


    http://endgameinteractive.co.uk
    Wednesday, January 18, 2012 3:39 PM
  • comment out this override and try to use following method:

    protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(IRibbonExtensibility).GUID)
                {
                    return new Ribbons(Application);
                }
                return base.RequestService(serviceGuid);
            }
    

     

    Of course you do not need to store Application object in your ribbon if you do not need to. Is ribbonUI passed when you use this initialisation routine?

     

    • Marked as answer by Kev Pearman Thursday, January 19, 2012 8:39 AM
    Wednesday, January 18, 2012 3:47 PM
  • RibbonLoad does not get called when i comment out the CreateRibbonExtensibilityObject() override and add your code

     

    EDIT:

    I forgot to comment out the CreateRibbonExtensibilityObject() override, when i do this the plug in throws an exception when i try and subscribe to any of the events i have declared in it


    http://endgameinteractive.co.uk
    • Edited by Kev Pearman Wednesday, January 18, 2012 3:56 PM
    Wednesday, January 18, 2012 3:53 PM
  • paste here full code for your addin class that registers ribbon and outlook version.
    Wednesday, January 18, 2012 3:59 PM
  • Here's an edited version of the code - Outlook 2010

    public partial class ThisAddIn
        {
            public static OurRibbon _ourRibbon;
     
            protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                _ourRibbon = new OurRibbon();
                return _ourRibbon;
            }
     
            #region startup / shutdown methods
     
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                Startup += ThisAddInStartup;
                Shutdown += ThisAddInShutdown;
            }
     
            private void ThisAddInStartup(object sender, EventArgs e)
            {
                _application = Application;
     
                //Specific start up code for my application here
                //....
            }
     
            private void ThisAddInShutdown(object sender, EventArgs e)
            {
                _application = null;
            }
     
     
        }

    and the RibbonXML file

    [ComVisible(true)]
        public class SYNETYRibbon : IRibbonExtensibility
        {
            private IRibbonUI _ribbon;
     
            #region IRibbonExtensibility Members
            public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("OurRibbon.xml");
            }
            #endregion
     
            public OurRibbon()
            {
            }
     
            public void RibbonLoad(IRibbonUI ribbonUI)
            {
                _ribbon = ribbonUI;
            }
        }

     

     


    http://endgameinteractive.co.uk
    • Edited by Kev Pearman Wednesday, January 18, 2012 4:09 PM
    Wednesday, January 18, 2012 4:08 PM
  • The service override also must be in the ThisAddin class, as it's public and exposed to COM.
     
    I usually pass an instance of a public RibbonHandler class to the service override, that handler implements Office.IRibbonExtensibility and contains the ribbon callbacks as well as the Ribbon_OnLoad() handler.
     
    For example:
     

    public partial class ThisAddIn

    {

        private RibbonHandler ribbon;

        protected override object RequestService(Guid serviceGuid)

        {

            if (serviceGuid == typeof(Office.IRibbonExtensibility).GUID)

            {

                if (ribbon == null)

                    ribbon = new RibbonHandler();

                return ribbon;

            }

            return base.RequestService(serviceGuid);

        }

    }

    [ComVisible(true)]

    public class Ribbon1 : Office.IRibbonExtensibility

    {

        //Ribbon UI object

        private Office.IRibbonUI ribbon;

        public void Ribbon_OnLoad(Office.IRibbonUI Ribbon)

        {

            this.ribbon = Ribbon;

        }
     
        // callbacks go here
    }

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:00103593-956d-4c98-8fae-ee313c1fa10a...

    RibbonLoad does not get called when i comment out the CreateRibbonExtensibilityObject() override and add your code

     

    EDIT:

    I forgot to comment out the CreateRibbonExtensibilityObject() override, when i do this the plug in throws an exception when i try and subscribe to any of the events i have declared in it


    http://endgameinteractive.co.uk

    Ken Slovak MVP - Outlook
    Wednesday, January 18, 2012 4:14 PM
    Moderator
  • Ken,

    I now have the following in my ThisAddIn.cs file

            protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                _ourRibbon = new OurRibbon();
                return _ourRibbon;
            }
     
            //private SYNETYRibbon ribbon;
            protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(IRibbonExtensibility).GUID)
                {
                    if (_ourRibbon2 == null)
                        _ourRibbon2 = new OurRibbon();
                    return _ourRibbon2;
                }
     
                return base.RequestService(serviceGuid);
            }

     

    I have tried each method on their own (Don't want to instantiate 2 ribbons) and both of the methods get called OK and i have a reference to my ribbon but that was never a problem before. In my OurRibbon class my IRibbonUI property is still null.

    I have added a break point to my RibbonLoad method

    public void RibbonLoad(IRibbonUI ribbonUI)
            {
                _ribbon = ribbonUI;
            }

    and the break point is not being hit (i'm fairly sure it was being hit but either way it isn't now)

    Any ideas?


    http://endgameinteractive.co.uk
    Wednesday, January 18, 2012 4:39 PM
  • I have no idea what CreateRibbonExtensibilityObject() is or why you're using it.
     
    Is OurRibbon a public class that is exposed to COM? Does it implement IRibbonExtensibility?

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Kev Pearman" <=?utf-8?B?S2V2IFBlYXJtYW4=?=> wrote in message news:019f7265-244b-416e-8066-b3ea82448690...

    Ken,

    I now have the following in my ThisAddIn.cs file

            protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                _ourRibbon = new OurRibbon();
                return _ourRibbon;
            }
     
            //private SYNETYRibbon ribbon;
            protected override object RequestService(Guid serviceGuid)
            {
                if (serviceGuid == typeof(IRibbonExtensibility).GUID)
                {
                    if (_ourRibbon2 == null)
                        _ourRibbon2 = new OurRibbon();
                    return _ourRibbon2;
                }
     
                return base.RequestService(serviceGuid);
            }

     

    I have tried each method on their own (Don't want to instantiate 2 ribbons) and both of the methods get called OK and i have a reference to my ribbon but that was never a problem before. In my OurRibbon class my IRibbonUI property is still null.

    I have added a break point to my RibbonLoad method

    public void RibbonLoad(IRibbonUI ribbonUI)
            {
                _ribbon = ribbonUI;
            }

    and the break point is not being hit (i'm fairly sure it was being hit but either way it isn't now)

    Any ideas?


    http://endgameinteractive.co.uk

    Ken Slovak MVP - Outlook
    Wednesday, January 18, 2012 5:58 PM
    Moderator
  • CreateRibbonExtensibilityObject() was mentioned in few places in msdn as a way to create ribbon 'faster' and more 'efficient' but it does not cover some scenarios, i.e. opening msg file from disk when outlook is not running, so always use override of RequestService. I also vaguely remember that you can specify name of method to be called, so it is not a name hardcoded. Where do you specify that RibbonLoad should be called? if nowhere, please change that method to 'public void OnLoad(IRibbonUI ribbon)'
    • Edited by DamianD Thursday, January 19, 2012 8:25 AM
    Thursday, January 19, 2012 8:24 AM
  • Ken,

    OurRibbon is COM visible, public and it implements IRibbonExtensibility

    As Damian said i believe overriding CreateRibbonExtensibilityObject came from an example i was using as a starting point for my plugin. I've taken it out and the plugin still seems to work the same with the override of RequestService in there.

     

    Damian,

    I have changed the method to be

    public void OnLoad(IRibbonUI ribbonUI)
            {
                _ribbon = ribbonUI;
            }

    But my breakpoint still isn't being hit

     


    http://endgameinteractive.co.uk
    Thursday, January 19, 2012 8:35 AM
  • Which was because i had specified a different name for the method in the XML file, doh!

    <customUI onLoad="Ribbon_Load"
    

    Now i've added the RequestService override the IRibbonUI object being passed in is no longer null, thanks for all the help.


    http://endgameinteractive.co.uk
    Thursday, January 19, 2012 8:38 AM