我已经在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
时获得回调?有了这个,我该怎么样获取此时在组合框中的值?