VSIX:在工具窗口中使用工具栏
在 Visual Studio 扩展包中,我想创建一个工具窗口(如解决方案资源管理器是一个工具窗口)并在此工具窗口中使用工具栏(如解决方案资源管理器有它自己的工具栏,其中包含“显示所有文件”“刷新”等)。
如果我的工具窗口处于活动状态工具提示显示工具栏上的命令。如果任何其他工具窗口处于活动状态,则不会显示它们。
然而,在解决方案资源管理器中,无论工具窗口是否处于活动状态,都会显示工具提示。
单击工具栏项也是如此。即使解决方案资源管理器不是活动工具窗口,也可以一键单击解决方案资源管理器工具栏项。
如果我的工具窗口不是活动工具窗口,则第一次单击会激活我的工具窗口,只有第二次单击才会单击该按钮。
有人知道如何在自定义 ToolWindows 中实现像解决方案资源管理器行为这样的行为吗?
谢谢 -M。
<UserControl x:Class="mklein.TestToolWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Name="MyToolWindow"
Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<ToolBar Grid.Row="0" Background="{DynamicResource {x:Static vsfx:VsBrushes.CommandBarGradientKey}}">
<ToolBar.Items>
<Button Command="SaveAs" ToolTip="Save new">
<Image Source="resources\add.png" />
</Button>
<!-- ... -->
</ToolBar.Items>
</ToolBar>
<ListBox Grid.Row="1" x:Name="ListboxSettings"
ItemsSource="{Binding}"
IsSynchronizedWithCurrentItem="True"
MouseDoubleClick="ListBox_MouseDoubleClick">
</ListBox>
</Grid>
</UserControl>
in a Visual Studio Extension Package I want to create a ToolWindow (like Solution Explorer is a ToolWindow) and use a ToolBar within this tool window (like Solution Explorer has it's own ToolBar with 'Show all Files' 'Refresh' and more).
If my ToolWindow is active tooltips are shown for the commands on the toolbar. They are not shown if any other tool window is active.
In Solution Explorer however, ToolTips are shown regardless of active the ToolWindow.
The same is true for clicking a toolbar item. A SolutionExplorer toolbar item can be clicked with one click even if solution explorer is not the active ToolWindow.
If my ToolWindow is not the active ToolWindow the first click activates my ToolWindow and only the second click clicks the button.
Does anyone know how to implement a behavior like Solution Explorers behavior in custom ToolWindows?
Thanks
-M.
<UserControl x:Class="mklein.TestToolWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Name="MyToolWindow"
Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowBackgroundKey}}" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<ToolBar Grid.Row="0" Background="{DynamicResource {x:Static vsfx:VsBrushes.CommandBarGradientKey}}">
<ToolBar.Items>
<Button Command="SaveAs" ToolTip="Save new">
<Image Source="resources\add.png" />
</Button>
<!-- ... -->
</ToolBar.Items>
</ToolBar>
<ListBox Grid.Row="1" x:Name="ListboxSettings"
ItemsSource="{Binding}"
IsSynchronizedWithCurrentItem="True"
MouseDoubleClick="ListBox_MouseDoubleClick">
</ListBox>
</Grid>
</UserControl>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您正在创建 WPF 工具栏,而不是本机 Visual Studio 工具栏(通过 VSCT 文件完成)。
查看此示例,演示如何托管“本机”工具栏,其中放置了 Visual Studio 命令。这是在工具窗口中的 Visual Studio 中创建新命令或重复使用现有命令的推荐方法。这还允许用户自定义命令并指定自己的键绑定。
That's because you're creating a WPF toolbar, not a native Visual Studio toolbar (which is done via a VSCT file).
Take a look at this sample demonstrating how to host a 'native' toolbar with Visual Studio commands placed in it. This is the recommended way to create new commands or re-use existing commands within Visual Studio in your toolwindow. This also allows the user to customize the commands and specify their own keybindings.