0

我想在 VSTO 中创建一个 ContextMenuListRange,我已经为 ContextMenuCell 创建了另一个 xml。如果我在另一个标签中添加列表范围,功能区会说“对象引用未设置为对象的实例。这是 xml 标签

<contextMenus>
<contextMenu idMso="ContextMenuCell">
  <menu id="MySubMenu" label="Visualization">
    <button id="contextBtn2" getEnabled="GetEnabled" getLabel="GetLabel" image="2Image" onAction="Part2Vis_Click"/>
    <button id="contextBtn3" getEnabled="GetEnabled" getLabel="GetLabel" image="3Image" onAction="Part3Vis_Click"/>
    <button id="contextBtn3Mod" getEnabled="GetEnabled" getLabel="GetLabel" image="3Module" onAction="Module3Vis_Click"/>
    <button id="contextBtnAdv" getLabel="GetLabel" onAction="BtnAdvClick" image="advImage"/>
    <button id="contextBtnOption" getLabel="GetLabel" onAction="BtnOptionClick" image="Settings"/>
    <button id="contextBtnHelpPage" getLabel="GetLabel" onAction="BtnHelpPageClick"  image="Help"/>
  </menu>     
</contextMenu>
</contextMenus> 
<contextMenus>
<contextMenu idMso="ContextMenuListRange">
  <menu id="MyContextNew" label="Visualization">
    <button id="contextBtn2d" getEnabled="GetEnabled" getLabel="GetLabel" image="2dImage" onAction="Part2DVis_Click"/>
    <button id="contextBtn3d" getEnabled="GetEnabled" getLabel="GetLabel" image="3dImage" onAction="Part3DVis_Click"/>
    <button id="contextBtn3dMod" getEnabled="GetEnabled" getLabel="GetLabel" image="3DModule" onAction="Module3DVis_Click"/>
    <button id="contextBtnAdv" getLabel="GetLabel" onAction="BtnAdvClick" image="advImage"/>
    <button id="contextBtnOption" getLabel="GetLabel" onAction="BtnOptionClick" image="Settings"/>
    <button id="contextBtnHelpPage" getLabel="GetLabel" onAction="BtnHelpPageClick"  image="Help"/>
  </menu>     
</contextMenu>

4

2 回答 2

0

将所有内容包含在 contextMenus 中

<contextMenus>
<contextMenu idMso="ContextMenuCell">
  <menu id="MySubMenu" label="Visualization">
    <button id="contextBtn2" getEnabled="GetEnabled" getLabel="GetLabel" image="2Image" onAction="Part2Vis_Click"/>
    <button id="contextBtn3" getEnabled="GetEnabled" getLabel="GetLabel" image="3Image" onAction="Part3Vis_Click"/>
    <button id="contextBtn3Mod" getEnabled="GetEnabled" getLabel="GetLabel" image="3Module" onAction="Module3Vis_Click"/>
    <button id="contextBtnAdv" getLabel="GetLabel" onAction="BtnAdvClick" image="advImage"/>
    <button id="contextBtnOption" getLabel="GetLabel" onAction="BtnOptionClick" image="Settings"/>
    <button id="contextBtnHelpPage" getLabel="GetLabel" onAction="BtnHelpPageClick"  image="Help"/>
  </menu>     
</contextMenu>

<contextMenu idMso="ContextMenuListRange">
  <menu id="MyContextNew" label="Visualization">
    <button id="contextBtn2d" getEnabled="GetEnabled" getLabel="GetLabel" image="2dImage" onAction="Part2DVis_Click"/>
    <button id="contextBtn3d" getEnabled="GetEnabled" getLabel="GetLabel" image="3dImage" onAction="Part3DVis_Click"/>
    <button id="contextBtn3dMod" getEnabled="GetEnabled" getLabel="GetLabel" image="3DModule" onAction="Module3DVis_Click"/>
    <button id="contextBtnAdv" getLabel="GetLabel" onAction="BtnAdvClick" image="advImage"/>
    <button id="contextBtnOption" getLabel="GetLabel" onAction="BtnOptionClick" image="Settings"/>
    <button id="contextBtnHelpPage" getLabel="GetLabel" onAction="BtnHelpPageClick"  image="Help"/>
  </menu>     
</contextMenu>

</contextMenus> 
于 2014-09-23T06:22:46.737 回答
0

避免重复按钮 ID 名称......我改变了并且工作正常

<contextMenus>
<contextMenu idMso="ContextMenuCell">
    <menu id="MySubMenu" label="Visualization">
        <button id="contextBtn2" getEnabled="GetEnabled" getLabel="GetLabel" image="2Image" onAction="Part2Vis_Click"/>
        <button id="contextBtn3" getEnabled="GetEnabled" getLabel="GetLabel" image="3Image" onAction="Part3Vis_Click"/>
        <button id="contextBtn3Mod" getEnabled="GetEnabled" getLabel="GetLabel" image="3Module" onAction="Module3Vis_Click"/>
        <button id="contextBtnAdv" getLabel="GetLabel" onAction="BtnAdvClick" image="advImage"/>
        <button id="contextBtnOption" getLabel="GetLabel" onAction="BtnOptionClick" image="Settings"/>
        <button id="contextBtnHelpPage" getLabel="GetLabel" onAction="BtnHelpPageClick"  image="Help"/>
  </menu>     
</contextMenu>

<contextMenu idMso="ContextMenuListRange">
  <menu id="MyContextNew" label="Visualization">
    <button id="contextBtn2d" getEnabled="GetEnabled" getLabel="GetLabel" image="2dImage" onAction="Part2DVis_Click"/>
    <button id="contextBtn3d" getEnabled="GetEnabled" getLabel="GetLabel" image="3dImage" onAction="Part3DVis_Click"/>
    <button id="contextBtn3dModX" getEnabled="GetEnabled" getLabel="GetLabel" image="3DModule" onAction="Module3DVis_Click"/>
    <button id="contextBtnAdvX" getLabel="GetLabel" onAction="BtnAdvClick" image="advImage"/>
    <button id="contextBtnOptionX" getLabel="GetLabel" onAction="BtnOptionClick" image="Settings"/>
    <button id="contextBtnHelpPageX" getLabel="GetLabel" onAction="BtnHelpPageClick"  image="Help"/>
  </menu>     
</contextMenu>

</contextMenus> 
于 2018-06-11T04:13:06.923 回答