Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Get Tab For Context Menu

Get Tab For Context Menu

Scheduled Pinned Locked Moved WPF
questionwpfwcfhelp
1 Posts 1 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups