开发者

How can I close all tabs in TabControlEx?

开发者 https://www.devze.com 2023-04-10 03:33 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消