Visual studio 2015 Visual Studio 2015工具栏组合,如何正确管理用户输入的值?
我在VSCT文件中使用以下设置为Visual Studio 2015的VSIX包中的工具栏定义了一个动态组合:Visual studio 2015 Visual Studio 2015工具栏组合,如何正确管理用户输入的值?,visual-studio-2015,vsix,vsx,vspackage,vsct,Visual Studio 2015,Vsix,Vsx,Vspackage,Vsct,我在VSCT文件中使用以下设置为Visual Studio 2015的VSIX包中的工具栏定义了一个动态组合: <Combo guid="cmdExplorerToolbarSearchGUID" id="cmdExplorerToolbarSearchID" priority="0x0" type="DynamicCombo" defaultWidth="50" idCommandList="cmdExplorerToolbarSearchGetListID">
<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>
最后,oncmdexplorerToolBarSearch选择了如下事件处理程序:
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
),则组合键将恢复到以前的值(“单位”),因为处理程序是用args.OutValue调用的!=IntPtr.Zero
当用户输入某个内容并将焦点从组合框移开而不按Enter
时,获得回调的技巧是什么?鉴于此,我如何获得此时组合框上的值?我没有尝试过这一点,但是如果您使用安装命令,您可以提供一个“已更改”的处理程序,该处理程序似乎应该在组合框中的文本更改时调用。这可以让你做你想做的事吗
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);
}
}
}