我有个问题。
在我的 WPF 应用程序中,如果我用鼠标中键按下 tabItem,则该 tabItem 应关闭。就像在火狐中一样。
但我尝试使用 MVVM 来做到这一点,并且我需要使用命令。我的 tabItems 也是动态创建的。
请帮助我!
谢谢你!
创建一个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>
最后将数据模板作为项目模板分配给选项卡控件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)