void TabHost_TabItemClosing(object sender, TabItemCancelEventArgs e)
 {
     if (e.TabItem.Content is IDisposable)
     {
         ((IDisposable)e.TabItem.Content).Dispose();
     }
 }
Пример #2
0
        /// <summary>
        /// Called by a child TabItem that wants to remove itself by clicking on the close button
        /// </summary>
        /// <param name="item"></param>
        public void RemoveItem(TabItem item)
        {
            // gives an opertunity to cancel the removal of the tabitem
            TabItemCancelEventArgs c = new TabItemCancelEventArgs(item);
            if (TabItemClosing != null)
                TabItemClosing(item, c);

            if (c.Cancel == true)
                return;

            var closable = Items.Cast<TabItem>().Count(t => t.AllowDelete);

            if (item.AllowDelete) closable--;

            // If there are no closable tabs left, move to home tab
            if (closable == 0)
                SelectedIndex = 0;

            this.Items.Remove(item);

            if (TabItemClosed != null)
                TabItemClosed(this, new TabItemEventArgs(item));
        }