Example #1
0
        public override void AddTabPane(Control control, object caption, object icon, Action closeAction)
        {
            ExtendedTabItem item = new ExtendedTabItem();
            item.Icon = icon;
            item.Header = caption;

            control.Height = Double.NaN;
            control.Width = Double.NaN;

            item.Content = control;

            tabPane.Items.Add(item);

            if (closeAction != null)
                tabPane.TabItemClosed += (sender, args) =>
                                         	{
                                         		if (item == args.TabItem)
                                         			closeAction.Invoke();
                                         	};
            item.Focus();
        }
Example #2
0
 private static void SetDimensions(ExtendedTabItem tabItem)
 {
     if (tabItem.Dimension == null)
     {
         // store the original size specifications of the tab
         tabItem.Dimension =
             new Dimension
                 {
                     Height = tabItem.Height,
                     Width = tabItem.Width,
                     MaxHeight = tabItem.MaxHeight,
                     MaxWidth = tabItem.MaxWidth,
                     MinHeight = tabItem.MinHeight,
                     MinWidth = tabItem.MinWidth
                 };
     }
     else
     {
         // restore the original values for the tab
         tabItem.BeginInit();
         tabItem.Height = tabItem.Dimension.Height;
         tabItem.Width = tabItem.Dimension.Width;
         tabItem.MaxHeight = tabItem.Dimension.MaxHeight;
         tabItem.MaxWidth = tabItem.Dimension.MaxWidth;
         tabItem.MinHeight = tabItem.Dimension.MinHeight;
         tabItem.MinWidth = tabItem.Dimension.MinWidth;
         tabItem.EndInit();
     }
 }
Example #3
0
 public TabItemEventArgs(ExtendedTabItem item)
 {
     TabItem = item;
 }
        /// <summary>
        /// Called by a child Header that wants to remove itself by clicking on the close button
        /// </summary>
        /// <param name="tabItem"></param>
        public void RemoveTabItem(ExtendedTabItem tabItem)
        {
            if (IsFixedSize)
                throw new InvalidOperationException("ItemsSource is Fixed Size");

            // gives an opertunity to cancel the removal of the tabitem
            var c = new TabItemCancelEventArgs(tabItem);
            if (TabItemClosing != null)
                TabItemClosing(tabItem, c);

            if (c.Cancel)
                return;

            if (ItemsSource != null)
            {
                var list = ItemsSource as IList;
                object listItem = ItemContainerGenerator.ItemFromContainer(tabItem);
                if (listItem != null && list != null)
                    list.Remove(listItem);
            }
            else
                this.Items.Remove(tabItem);

            if (TabItemClosed != null)
                TabItemClosed(this, new TabItemEventArgs(tabItem));
        }
 public void RemoveAllTabsBut(ExtendedTabItem thiz)
 {
     ArrayList list = new ArrayList(Items);
     foreach (ExtendedTabItem item in list)
     {
         if(item!=thiz)
             RemoveTabItem(item);
     }
 }
        /// <summary>
        ///     Add a new Header
        /// </summary>
        public void AddTabItem()
        {
            if (IsFixedSize)
                throw new InvalidOperationException("ItemsSource is Fixed Size");

            int i = this.SelectedIndex;

            // give an opertunity to cancel the adding of the tabitem
            CancelEventArgs c = new CancelEventArgs();
            if (TabItemAdding != null)
                TabItemAdding(this, c);

            if (c.Cancel)
                return;

            ExtendedTabItem tabItem;

            // Using ItemsSource property
            if (ItemsSource != null)
            {
                IList list = (IList)ItemsSource;
                NewTabItemEventArgs n = new NewTabItemEventArgs();
                if (NewTabItem == null)
                    throw new InvalidOperationException("You must implement the NewTabItem event to supply the item to be added to the tab control.");

                NewTabItem(this, n);
                if (n.Content == null)
                    return;

                if (i == -1 || i == list.Count - 1 || AddNewTabToEnd)
                    list.Add(n.Content);
                else
                    list.Insert(++i, n.Content);

                tabItem = (ExtendedTabItem)this.ItemContainerGenerator.ContainerFromItem(n.Content);
            }
            else
            {
                // Using Items Property
                tabItem = new ExtendedTabItem { Header = "New Tab" };

                if (i == -1 || i == this.Items.Count - 1 || AddNewTabToEnd)
                    this.Items.Add(tabItem);
                else
                    this.Items.Insert(++i, tabItem);
            }

            if (TabItemAdded != null)
                TabItemAdded(this, new TabItemEventArgs(tabItem));
        }