一般在VSTO中,使用可视化编辑器来进行Ribbon功能区的开发,控件之间的引用和修改属性值与winform开发没有区别,是非常方便的,但为了实现更复杂的功能,不得不转到XML编辑器下的开发,但似乎控件间的互相访问就不是那么直接了,因为XML设计器使用了在fluent ui下大量的回调机制,也就是说,每个控件的属性的修改一定要通过回调方法,另一方面由于有缓存机制在,界面的更新还需要由InvalidateControl来触发。

      如下示例,展示了通过点击按钮修改label控件的值。

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group >
          <labelControl />
          <button />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

 代码部分添加:

 private string _label = "Label";

public string GetLabel(Office.IRibbonControl control)
{
return _label;
}

public void Click(Office.IRibbonControl control)
{
_label = "Changed By Button";
ribbon.InvalidateControl("mylabel");
}

注意这样几点:

1 在XML中labelControl的label和getLabel不能同时出现,否则vsto启动时看不到label控件

2 所有控件至少有一个id属性,否则vsto启动时看不到控件

3 回调函数一定要按照代理原型定义 


 

相关文章:

  • 2021-10-24
  • 2021-08-10
  • 2022-12-23
  • 2021-06-05
  • 2021-05-04
  • 2021-12-05
猜你喜欢
  • 2022-01-08
  • 2021-09-19
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案