【问题标题】:Retrieve data of custom VSTO addin检索自定义 VSTO 插件的数据
【发布时间】:2019-04-04 01:32:58
【问题描述】:

我正在使用 VSTO 插件添加一个可能对我有用的功能。 所以到目前为止我所做的就是将我的ribbon.xml 声明如下:

<tabs>
  <tab idMso="TabAppointment" insertAfterMso="TabAddIns">
    <group id="TripGroup" label="Add Trip">
      <dropDown id="TripBooking_Tab_AddMeetingBefore"
                getLabel="GetLabel"
                getSelectedItemIndex="TripBooking_Tab_AddMeeting_GetSelectedItemIndex"
                getItemCount="TripBooking_Tab_AddMeeting_GetItemCount"
                getItemID="TripBooking_Tab_AddMeeting_GetItemID"
                getItemLabel="TripBooking_Tab_AddMeeting_GetItemLabel"
                onAction="TripBooking_Tab_AddMeetingBefore_OnAction"/>
      <separator/>
      <dropDown id="TripBooking_Tab_AddMeetingAfter"
                getLabel="GetLabel"
                getSelectedItemIndex="TripBooking_Tab_AddMeeting_GetSelectedItemIndex"
                getItemCount="TripBooking_Tab_AddMeeting_GetItemCount"
                getItemID="TripBooking_Tab_AddMeeting_GetItemID"
                getItemLabel="TripBooking_Tab_AddMeeting_GetItemLabel"
                onAction="TripBooking_Tab_AddMeetingAfter_OnAction"/>
    </group>
  </tab>
</tabs>

一切都像一个魅力,我在 UI 中得到了我的 2 dropdown。 现在的问题是:我如何为每个新约会检索dropdown 的值?

【问题讨论】:

  • 如果你贴出getSelectedItemIndexgetItemCountgetItemIDgetItemLabel的过程,我可以举一个更详细的例子。

标签: c# vsto outlook-addin add-in


【解决方案1】:

我会在dropDownOnAction 事件和加载默认值时设置变量。

public void OnAction_Dropdown(Office.IRibbonControl control, string itemId, int index)
{
    try
    {
        switch (control.Id) //do a lookup of the value from your list based on the index
        {
            case "TripBooking_Tab_AddMeetingBefore":
                // set a variable here
                break;
            case "TripBooking_Tab_AddMeetingAfter":
                // set a variable here
                break;
            default:
                break;
        }

    }
    catch (Exception ex)
    {
        // format message
        var userMessage = new StringBuilder()
            .AppendLine("Contact your system administrator.")
            .AppendLine("Procedure: " + caller.Name.Trim())
            .AppendLine("Description: " + ex.ToString())
            .ToString();
        MessageBox.Show(userMessage, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

}

【讨论】:

  • 我试过了,但是如何在用户当前创建的约会实例 (Outlook.Appointment) 中检索这些值?
  • 我认为Microsoft article 可能就是您要找的。​​span>
【解决方案2】:

您无法检索当前值。相反,您需要将它放在您的插件中(作为变量/字段)并让控件呈现它,对控件事件做出反应并相应地更新您的值。

当您需要该值时,您只需使用您的内部变量。

这种不允许用户在运行时直接访问或操作功能区控件的方法是一件好事,并且可以防止加载项相互破坏或破坏内置 UI,就像它曾经在预功能区中一样(命令栏)时间。微软在 2007 年首次推出功能区时就采用了这种方法。

有点相关: How to set default value in dropdown control for Excel custom ribbon control

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    相关资源
    最近更新 更多