我遇到问题。 在我的WPF应用程序中,如果我用鼠标中键按TabItem,这个tabItem应该关闭。就像在FireFox中一样。 但我尝试使用MVVM来做到这一点,我需要使用命令。此外我的tabItems是动态创建的。 帮我看看! 谢谢!通过单击中间按钮来关闭TabItem
3
A
回答
6
为您的标签项DataTemplate
这样的:
<DataTemplate x:Key="ClosableTabTemplate">
<Border>
<Grid>
<Grid.InputBindings>
<MouseBinding Command="ApplicationCommands.Close" Gesture="MiddleClick" />
</Grid.InputBindings>
<!-- the actual contents of your tab item -->
</Grid>
</Border>
</DataTemplate>
在应用程序窗口中,添加一个关闭命令
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.Close" Executed="CloseCommandExecuted" CanExecute="CloseCommandCanExecute" />
</Window.CommandBindings>
最后的数据模板项目模板分配给你的标签控制。
0
您可以添加MouseBinding
某些InputBindings
也许?
+0
我的tabItems是动态创建的。我应该在代码后面添加一个mouseBinding吗? – Yevgeniy
+0
@Yevgeniy:这将是一个选项,不幸的是,这不能通过样式完成... –
相关问题
- 1. 如何通过单击按钮来关闭JFrame?
- 2. 关闭blockUI通过按钮
- 3. 如何通过单击“取消”按钮关闭窗口?
- 4. 通过单击X按钮
- 5. 通过单击按钮
- 6. 用按钮单击关闭JFrame
- 7. 关闭按钮上的容器单击
- 8. C#Winfoms Toolstripdropdown关闭按钮单击
- 9. App Force在按钮单击时关闭
- 10. 应用程序关闭按钮单击
- 11. 单击按钮时不要关闭NSAlert
- 12. 关闭按钮上的窗口单击
- 13. 关闭窗口按钮单击
- 14. Alertify.alert未关闭按钮单击
- 15. 如何通过按下按钮来关闭Tkinter窗口?
- 16. 跳转到下一个tabitem通过点击按钮
- 17. 如何通过单击按钮来更改ImageView中的图片?
- 18. iPhone:可以通过UITextField清除按钮来关闭键盘吗?
- 19. 通过单击带有动画的按钮关闭表格视图(swift)
- 20. 通过单击一个gwt按钮来伪造一个表单
- 21. 通知栏关闭按钮
- 22. 通过单击关闭关闭一个实况搜索框它
- 23. 通过单击按钮创建表格
- 24. 如何检测通过Alt + F4关闭的浏览器窗口或单击窗口的关闭按钮?
- 25. 如何通过单击关闭按钮关闭批处理脚本时运行批处理命令
- 26. 通过在AS2应用程序中单击外部来关闭下拉菜单?
- 27. 我想通过单击十字按钮关闭另一个页面使按钮在一个页面上可见
- 28. 如何通过单击TabbarItem按钮来获取Tabbar项按钮的Click事件?
- 29. 通过单击按钮来更改控件的可见性
- 30. 如何通过单击按钮来更改Strings.xml?
当我处理CloseCommandExecuted时,e.Source返回一个TabControl对象。我如何获得TabItem对象? – Brandon