如何访问 Office 插件中的后台复选框值? [英] How to access backstage checkbox value in an Office addin?
问题描述
我在 Setting.settings 文件中有一个布尔属性 Settings.Default.MarkAsRead
,我可以在 Ribbon 类中访问它.我想要做的是根据此属性的值在后台部分设置复选框的值.此外,如果用户修改它,我将需要保存新值.
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?
这是我的(简化的)xml:
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>
推荐答案
我没有找到从 Ribbon_Load
方法访问 xml 元素的方法,所以我在我使用 GetPressed
和 OnAction
回调更新的功能区类:
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;
}
这篇关于如何访问 Office 插件中的后台复选框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!