7

我使用 VSCT 文件中的此设置为 Visual Studio 2015 的 VSIX 包中的工具栏定义了一个动态组合:

  <Combo guid="cmdExplorerToolbarSearchGUID" id="cmdExplorerToolbarSearchID" priority="0x0" type="DynamicCombo"
      defaultWidth="50" idCommandList="cmdExplorerToolbarSearchGetListID">
    <Parent guid="grpExplorerToolbar3GUID" id="grpExplorerToolbar3ID" />
    <CommandFlag>DynamicVisibility</CommandFlag>
    <CommandFlag>IconAndText</CommandFlag>
    <CommandFlag>StretchHorizontally</CommandFlag>
    <Strings>
      <CanonicalName>cmdExplorerToolbarSearch</CanonicalName>
      <ButtonText>Search</ButtonText>
      <ToolTipText>Search elements in the model explorer</ToolTipText>
    </Strings>
  </Combo>

</Combos>

对应的DynamicStatusMenuCommand实例定义如下:

    command = new DynamicStatusMenuCommand(
        new EventHandler(this.OnPopUpMenuDisplayAction),
        new EventHandler(this.OnCmdExplorerToolbarSearchSelected),
        new CommandID(CmdExplorerToolbarSearchGUID, CmdExplorerToolbarSearchID));
    commands.Add(command);

    command = new DynamicStatusMenuCommand(
        new EventHandler(this.OnPopUpMenuDisplayAction),
        new EventHandler(this.OnCmdExplorerToolbarSearchGetList),
        new CommandID(CmdExplorerToolbarSearchGUID, CmdExplorerToolbarSearchGetListID));
    commands.Add(command);

最后是OnCmdExplorerToolbarSearchSelected这样的事件处理程序:

private void OnCmdExplorerToolbarSearchSelected(object sender, EventArgs e)
{
    // Process the event arguments

    OleMenuCmdEventArgs args = e as OleMenuCmdEventArgs;
    if (args != null)
    {
        // Process values

        string inValue = args.InValue as string;
        IntPtr outValue = args.OutValue;

        if (outValue != IntPtr.Zero)
        {
            // When outValue is not null, the IDE is requesting the current value for the combo

            Marshal.GetNativeVariantForObject(this.SearchHandler.CurrentValue, outValue);
        }
        else if (inValue != null)
        {
            this.SearchHandler.Search(this.PresentationModel3ExplorerToolWindow.Explorer, inValue);
        }
    }
}

这会在工具箱中产生一个很好的组合:

工具栏的打印屏幕

问题是,例如,如果用户输入“Unit”并按下Enter事件处理程序,则使用 inValue != null 调用事件处理程序并执行搜索。但是,如果随后他输入其他内容(例如:Customer)并按下Tab(否Enter),则组合将恢复为先前的值(“Unit”),因为使用 args.OutValue != IntPtr.Zero 调用处理程序。

当用户输入某些内容并将焦点从组合移开而不按 时,获得回调的技巧是什么Enter?而且,鉴于此,我如何才能获得当时组合的价值?

4

1 回答 1

0

我还没有尝试过,但是如果您使用OleMenuCommand安装命令,则可以提供“已更改”处理程序,似乎只要组合框中的文本发生更改,就应该调用它。这可能会让你做你想做的事?

于 2017-01-06T06:55:03.070 回答