private void SetNextTab()
        {
            if (this.Tabs.Children.Count == 1)
            {
                return;
            }

            int checkIndex = this.previousIndex - 1;

            TabHeader item = null;

            while (checkIndex >= 0)
            {
                item = this.TabItem(checkIndex);

                if (item != null)
                {
                    this.SetCurrent(checkIndex);

                    return;
                }

                checkIndex--;
            }

            checkIndex = this.previousIndex + 1;

            while (checkIndex <= this.tabIndex)
            {
                item = this.TabItem(checkIndex);

                if (item != null)
                {
                    this.SetCurrent(checkIndex);

                    return;
                }

                checkIndex++;
            }
        }
        public void SetHeaderName(int index, string name)
        {
            while (index > (this.Tabs.Children.Count - 1))
            {
                index--;

                if (index < 0)
                {
                    return;
                }
            }

            TabHeader tabItem = this.Tabs.Children[index] as TabHeader;

            if (tabItem == null)
            {
                return;
            }

            tabItem.HeaderText = name;
        }
        private void PerformItemSet(TabHeader item)
        {
            if (item == null)
            {
                return;
            }

            this.UnSetPrevious();

            if (!item.IsTabEnabled)
            {
                return;
            }

            this.SetCurrent(item.TabIndex);

            if (this.OnTabSelected != null)
            {
                this.OnTabSelected(item, item.TabIndex);
            }
        }
        private void Items_OnPropertyChangedEvent(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                foreach (UserControlBase item in e.NewItems)
                {
                    item.TabIndex = -1;

                    if (this.MaxTabls > 0 && this.Items.Count > this.MaxTabls)
                    {
                        MessageBox.Show($"Maximum Tab Limit of {this.MaxTabls} reached");

                        this.Items.Remove(item);

                        return;
                    }

                    TabHeader header = new TabHeader();

                    header.RotationAngle = this.DockLocation == VerticalTabDocLocationEnum.Left ? 90 : 270;

                    header.IsVertical = true;

                    header.OnClick += this.Item_Click;

                    header.OnCloseClick += this.CloseButton_Click;

                    header.CanClose = item.ShowCloseButton;

                    header.HeaderText = item.Title;

                    header.TabIndex = this.tabIndex;

                    item.SizeChanged += this.Control_SizeChanged;

                    item.VerticalAlignment = VerticalAlignment.Stretch;

                    item.HorizontalAlignment = HorizontalAlignment.Stretch;

                    item.Tag = header;

                    header.IsSelected = true;

                    this.Tabs.Children.Add(header);

                    item.TabIndex = this.tabIndex;

                    this.UnSetPrevious();

                    //this.Content = item;

                    this.previousIndex = this.tabIndex;

                    this.tabIndex++;
                }

                break;

            case NotifyCollectionChangedAction.Remove:

                foreach (UserControlBase removeItem in e.OldItems)
                {
                    if (this.Content == removeItem)
                    {
                        this.Content = null;

                        if (removeItem.TabIndex == this.previousIndex)
                        {
                            this.SetNextTab();
                        }
                    }

                    TabHeader tab = this.TabItem(removeItem.TabIndex);

                    if (tab != null)
                    {
                        this.Tabs.Children.Remove(tab);
                    }

                    removeItem.SizeChanged -= this.Control_SizeChanged;
                }

                break;

            case NotifyCollectionChangedAction.Reset:

                this.Items.Clear();

                this.Content = null;

                this.Tabs.Children.Clear();

                this.SelectedIndex = 0;

                this.tabIndex = 0;

                break;
            }
        }
        public void SetActive(int index)
        {
            TabHeader tabItem = (TabHeader)this.Tabs.Children.GetByIndex(index);

            this.PerformItemSet(tabItem);
        }
        public object SelectedItem()
        {
            TabHeader header = this.TabItem(this.SelectedIndex);

            return(this.Items[header.TabIndex]);
        }