Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:50:04+00:00 2026-05-25T02:50:04+00:00

I have a tab control in a window. The tabs all have simple context

  • 0

I have a tab control in a window. The tabs all have simple context menus which (are supposed to) allow the user to close them. However, when I click close, nothing happens.

Here is the event handler

void closeTab_Click(object sender, RoutedEventArgs e)
{
    Tabs.Items.Remove((MenuItem)sender);
}

I’ve looked around about closing tabs, but none of the articles I found went into much detail about how to actually close the tab.

New problem:

void closeTab_Click(object sender, RoutedEventArgs e) 
{ 
    MenuItem close = (MenuItem)sender; 
    Tabs.Items.Remove(Convert.ToInt32(close.Name.Remove(0,3))); 
} 

The context menu item is named thusly:

Name = "Tab" + Tabs.Items.Count.ToString(), 

It still does nothing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:50:05+00:00Added an answer on May 25, 2026 at 2:50 am

    The menu item is not the tab. You cannot remove it from the TabControl. You need a reference to the tab to which the MenuItem belongs. This can be done in various ways.


    I see you tried some rather hacky things there with names and string manipulation, here would be a more clean approach which does not require any of that:

    var target = (FrameworkElement)sender;
    while (target is ContextMenu == false)
        target = (FrameworkElement)target.Parent;
    var tabItem = (target as ContextMenu).PlacementTarget;
    Tabs.Items.Remove(tabItem);
    

    This gets the parent until it finds the ContextMenu and gets the TabItem from the PlacementTarget.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a mvvm app that the main window is a tab control. i
I have a tab control bound to an observablecollection for dynamic tabs as follows:
I have a tab navigator control and I would like to make all of
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
i have a tab control with 2 tabs. the content of each tab is
I have a windows form with a primary tab control and multiple tabs (tabTest1,
I have a search box with JavaScript and CSS tabs on it which control
I have a search box with JavaScript and CSS tabs on it which control
I have three tabs in a Windows Forms tab control. Currently in Tab1 I
Right now, I have a WPF window where all the tab labels of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.