Get Tab For Context Menu
WPF
1
Posts
1
Posters
6
Views
1
Watching
-
I have a tab control, and I have a header template and style:
<!--Tab Item Header Template--> <DataTemplate x:Key="CustomHeaderTemplate"> <DockPanel LastChildFill="True"> <TextBlock Text="{Binding FileName}" VerticalAlignment="Center" FontSize="14"/> <Button Command="{Binding DataContext.CloseTabCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" CommandParameter="{Binding}" VerticalAlignment="Center" Height="22" Width="22" Background="SteelBlue" Margin="3,0,0,0"> <Path Data="M1,9 L9,1 M1,1 L9,9" Stroke="White" StrokeThickness="2" /> </Button> </DockPanel> </DataTemplate> <!--Tab Item Style--> <Style TargetType="TabItem"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}" > <MenuItem Header="Close Tab" Command="{Binding Source={StaticResource Proxy}, Path=Data.CloseTabCommand}" CommandParameter="{Binding}"/> <MenuItem Header="Close All Tabs" Command="{Binding Source={StaticResource Proxy}, Path=Data.CloseAllTabsCommand}" CommandParameter="{Binding}"/> <MenuItem Header="Close All But This" Command="{Binding Source={StaticResource Proxy}, Path=Data.CloseAllButThisTabCommand}" CommandParameter="{Binding}"/> </ContextMenu> </Setter.Value> </Setter> </Style>
The problem is that if I right-click a tab that is NOT selected, and choose one of the close options, the SELECTED tab is closed. How can I specify that correct tab item in the command?