I'm working with the WPF TabControlEx (close tab开发者_运维技巧s).
I'm looking a way to close all the tabs with a ContextMenu in tabs.
I'm using MVVM.
<Style TargetType="{x:Type TabItem}">
...
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Close tab" Command="{Binding CloseWorkSpaceCommand}" /> <!-- OK -->
<Separator />
<MenuItem Header="Close other tabs" Command="{Binding ...Command}" />
<Separator />
<MenuItem Header="Close all tabs" Command="{Binding ...Command}" />
</ContextMenu>
</Grid.ContextMenu>
Any suggestions?
Thanks a lot for all your help
If its a normal TabControl
then i assume you have :
<TabControl ItemsSource="{Binding Path=MyTabs}"></TabControl>
A tab controls with a collection set to the Item source property
Set MyTabs=new List<Tab>()
on the Execute
action for CloseWorkSpaceCommand
MyTabs will be a property in ViewModel of your View. ViewModel should Implement INotifyPropertyChanged
精彩评论