我遇到问题。 在我的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. RadContextMenu关闭按钮单击
- 3. 关闭blockUI通过按钮
- 4. 如何通过点击关闭按钮关闭弹出窗口?
- 5. 如何通过单击“取消”按钮关闭窗口?
- 6. 按钮关闭UIViewController中单击
- 7. 如何通过点击打开按钮区域外部来关闭菜单?
- 8. 通过单击按钮
- 9. 通过单击X按钮
- 10. 通过单击按钮禁用按钮
- 11. 强制关闭按钮单击
- 12. App Force在按钮单击时关闭
- 13. 用按钮单击关闭JFrame
- 14. 应用程序关闭按钮单击
- 15. 关闭按钮上的容器单击
- 16. Alertify.alert未关闭按钮单击
- 17. C#Winfoms Toolstripdropdown关闭按钮单击
- 18. 关闭按钮上的窗口单击
- 19. 单击按钮时不要关闭NSAlert
- 20. 单击按钮后请勿关闭AlertDialog
- 21. 单击按钮关闭网页
- 22. 关闭窗口按钮单击
- 23. 如何通过按下按钮来关闭Tkinter窗口?
- 24. 添加关闭按钮div来关闭拳击
- 25. Android按钮点击按钮时关闭
- 26. 跳转到下一个tabitem通过点击按钮
- 27. 关闭按钮点击
- 28. 通过关闭按钮传递视图
- 29. 通过按钮关闭bootstrap offcanvas
- 30. 关闭按钮上的键盘单击该关闭片段
当我处理CloseCommandExecuted时,e.Source返回一个TabControl对象。我如何获得TabItem对象? – Brandon