问题描述
我使用功能区XML文件创建了一个自定义标签,其中包含一个切换按钮.该按钮用于切换自定义任务窗格的可见性,并且效果很好.问题在于,当用户关闭自定义任务窗格时,切换按钮现在不同步.如何以编程方式访问切换按钮,以便更改其IsChecked值?
I used a ribbon XML file to create a custom tab which contains a togglebutton. The button is meant to toggle the visibility of a custom task pane and works great. The problem is that when the user close the custom task pane, the toggle button is now out of sync. How do I programmaticly access the togglebutton so I can change its IsChecked value?
推荐答案
您需要处理 VisibleChanged 事件.将以下方法添加到ThisAddIn类中-当用户通过单击关闭"按钮(X)关闭任务窗格时,此方法将更新功能区上切换按钮的状态.
You need to handle the VisibleChanged event. Add the following method to your ThisAddIn class - when the user closes the task pane by clicking the Close button (X), this method updates the state of the toggle button on the Ribbon.
private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
{
Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked =
taskPaneValue.Visible;
}
(请参阅演练:同步具有功能区按钮的自定义任务窗格)
这篇关于Office功能区:如何使用XML创建功能区时访问控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!