【问题标题】:How to detect the state of a toggle button on a ribbon?如何检测功能区上切换按钮的状态?
【发布时间】:2012-09-26 22:51:13
【问题描述】:

我在功能区中添加了一个切换按钮,现在我想将其状态发送到另一个对象。代码如下。

public void Butt_Click(Office.IRibbonControl control)
{
  something.SendButtVal(control.State);
}

当然,control.State 不起作用。我怀疑我需要将control 转换为ToggleButton 或类似的东西,但智能感知什么也没给我...

我可以看到接口IRibbonControl 的API 是here,但我想查看实现类的列表,例如JavaDocs。我怎么去那里?

编辑

请注意,我问的是功能区组件。请参阅方法签名。它是功能区上的切换按钮。问题是我没有得到Checked 属性,并且(可能)需要将control 转换为正确的类型。

【问题讨论】:

    标签: c# vsto ribbon togglebutton


    【解决方案1】:

    您需要更改您的签名。切换按钮不正确。详情请见here

    public void ToggleButtonOnAction(IRibbonControl control, bool pressed)
    {
      MessageBox.Show("ToggleButton was switched " + pressed ? "on" : "off");
    }
    

    【讨论】:

    • 我认为它在 Office 2007 中的工作方式与 Office 2010 类似,但我使用的是 Office 2010,并且没有调用带有 bool 参数的方法。有一篇文章here说应该是但不是!
    • 它在那里,确保在您的功能区 XML 中您的按钮被定义为 而不是
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    相关资源
    最近更新 更多