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 7938885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:55:51+00:00 2026-06-03T22:55:51+00:00

Customizing TabItem I have a TabControl bound to my ViewModel i also want to

  • 0

Customizing TabItem

I have a TabControl bound to my ViewModel i also want to remove tabs but i cant see the canges the tabitems see default without changes

    <TabControl
        Margin="5 5 5 0"
        Grid.Row="1"
        ItemsSource="{Binding Path=ListTabItem}"
        SelectedIndex="{Binding Path=CurrentTabItemIndex}"
        x:Name="Workspace" Background="White">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <cmd:EventToCommand
                Command="{Binding ChangeTabCommand}"
                CommandParameter="{Binding SelectedItem, ElementName=Workspace}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <!--Here is my tabHeader-->
        <TabControl.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Header}" />                        
                    <Button Content="X" Command={Binding CloseTabCommand}
                      CommandParameter="{Binding SelectedItem, ElementName=Workspace}"/>
                </StackPanel>
            </DataTemplate>
        </TabControl.ItemTemplate>            
    </TabControl>

EDIT:

I get a working style, but i have the problem when close a tab dont release the memory:

    <Style x:Key="HeaderTabItem" TargetType="TabItem">
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Button                                
                            Width="20"
                            Height="20"
                            Margin="-3 0 5 0"
                            Padding="2"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            BorderBrush="{x:Null}" Background="{x:Null}" Foreground="{x:Null}"
                            DataContext="{Binding DataContext, ElementName=Workspace}"
                            Command="{Binding Path=CloseTabCommand}"
                            CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TabItem, AncestorLevel=1}}" Content="X"/>
                        <ContentControl
                            Grid.Column="1" 
                            VerticalAlignment="Center"
                            HorizontalAlignment="Left"
                            Content="{Binding Path=Header, RelativeSource={RelativeSource FindAncestor, AncestorType=TabItem, AncestorLevel=1}}" />
                    </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

in my ViewModel

    CloseTabCommand = new RelayCommand<TabItem>(tab =>
    {
        if (null == tab) return;
        ListTabItem.Remove(tab);
    },
    tab =>
    {
        return ListTabItem.IndexOf(tab) == CurrentTabItemIndex;
    });

any ideas?

  • 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-06-03T22:55:53+00:00Added an answer on June 3, 2026 at 10:55 pm

    WPF controls tend to not dispose themselves appropriately unless their DataContext has been cleared (which seems like kind of a hack). Try this:

    CloseTabCommand = new RelayCommand<TabItem>(tab =>
    {
        if (null == tab) return;
    
        tab.DataContext = null;
    
        ListTabItem.Remove(tab);
    },
    tab =>
    {
        return ListTabItem.IndexOf(tab) == CurrentTabItemIndex;
    });
    

    Also, keep in mind that you may not see the memory released immediately. Due to how Garbage Collection works in .NET, your application may need to wait/other events for Garbage Collection to actually occur and memory to be cleared.

    If you really want to, you can call GC.Collect(), but I would do this only if you are unconvinced that the memory is being freed and I would only put it in to debug and ensure that the objects are being freed. After you confirm, remove it and allow the Garbage Collector to do its job.

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

Sidebar

Related Questions

I'm customizing a UITableView . I want to hide the line separating on the
After customizing the devise redirects to call and i want to perform an action
I'm currently customizing the bluescale theme for Magento. I have moved the position of
I'm customizing a Wordpress site, and want to alter a file in the wp-includes
I tried the new Customizing API for iOS 5 and have some problems I
I am customizing my table cells. I have this code (simplified) which is giving
I am customizing the insert SQL generated by hibernate and have hit an issue.
I am working on customizing TFS workitem template for quite a while. But I
I am customizing wordpress blog and I have a need to make custom sidebar
I am working on customizing the layout of a Silverlight Toolkit Chart. I have

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.