How to access backstage checkbox value in an Office addin?

喜欢而已 提交于 2019-12-19 04:01:50

问题


I have a boolean property Settings.Default.MarkAsRead in the Setting.settings file, which I can access in my Ribbon class. What I'd like to do is set the value of a check box in my backstage section depending on the value of this property. Also if the user modifies it, I'll need to save the new value.

Any way I can do this?

This is my (simplified) xml:

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" 
         xmlns="http://schemas.microsoft.com/office/2009/07/customui"> 
  <backstage>
    <tab id="MyBackstageSection" label="MyBackstageSection"
                columnWidthPercent="30" insertAfterMso="TabInfo" visible="true" >
      <firstColumn>
        <group id="grpOne" label="Configuration">
          <bottomItems>

              <checkBox id="markAsRead" label="Mark as read"
                                 getPressed="markAsRead_GetPressed" />

              <button id="save" label="Save Preferences" onAction="save_Click"/>

          </bottomItems>         
        </group>
      </firstColumn>
    </tab>
  </backstage>
</customUI>

回答1:


I didn't find a way to access the xml elements from the Ribbon_Load method, so I've created a boolean property in the ribbon class that I update using the GetPressed and OnAction callbacks:

xml:

<checkBox id="markAsRead" label="Mark as read" 
            onAction="markAsRead_OnAction" getPressed="markAsRead_GetPressed"/>

c#:

    private bool MarkAsRead { get; set; }

    public bool markAsRead_GetPressed(Office.IRibbonControl control)
    {
        this.MarkAsRead = Settings.Default.MarkAsRead;
        return this.MarkAsRead;
    }

    public void markAsRead_OnAction(Office.IRibbonControl control, bool isPressed)
    {
        this.MarkAsRead = isPressed;
    }


来源:https://stackoverflow.com/questions/8039187/how-to-access-backstage-checkbox-value-in-an-office-addin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!