Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is what I've been using, and as far as I can tell it removes the tabitem from memory. The problem with leaving a timer inside of the tabitem, is that the GC won't collect and dispose of it because it detects that the timer is still in use.</p> <p>The Code:</p> <pre><code>namespace Reports.Controls { /// &lt;summary&gt; /// Interaction logic for Test.xaml /// &lt;/summary&gt; public partial class ReportTab : TabItem { public delegate void CloseEvents(ReportTab TabIndex); public event CloseEvents Closing; public ReportTab(string Title) { InitializeComponent(); tbTitle.Text = Title; } private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { Closing(this); } } } </code></pre> <p>The xaml:</p> <pre><code>&lt;TabItem x:Class="Reports.Controls.ReportTab" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" &gt; &lt;TabItem.Header&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="Main" Name="tbTitle" Margin="0,0,8,0"/&gt; &lt;Image Height="13" Source="pack://application:,,/Images/Icons/close.png" MouseLeftButtonUp="Image_MouseLeftButtonUp"/&gt; &lt;/StackPanel&gt; &lt;/TabItem.Header&gt; &lt;Grid&gt; //Tabitem stuff &lt;/Grid&gt; &lt;/TabItem&gt; </code></pre> <p>Here's the page with the Tabcontrol to add a tab:</p> <pre><code>void AddTab(string Title) { Controls.ReportTab rt = new Controls.ReportTab(Title); rt.Closing += new Controls.ReportTab.CloseEvents(rt_Closing); tabControl.SelectedIndex = tabControl.Items.Add(rt); } /// &lt;summary&gt; /// Moves the Tab Control back to the Main tab /// after a tab is removed /// &lt;/summary&gt; /// &lt;param name="TabIndex"&gt;&lt;/param&gt; void rt_Closing(Controls.ReportTab TabIndex) { tabControl.Items.Remove(TabIndex); //This resets the tabcontrol back to it's first tabindex tabControl.SelectedIndex = 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload