/// <summary>
        /// Get the value of SelectedIndex.
        /// </summary>
        /// <param name="item">The model item for a TabControl.</param>
        /// <returns>SelectedIndex of the TabControl.</returns>
        public static int GetDesignTimeSelectedIndex(ModelItem item)
        {
            int selectedIndex = item.GetDesignerProperty(DesignTimeSelectedIndexProperty);

            // check if that tab is really active. If not, then return -1 (none of the tabs are active
            if (item.Content != null &&
                item.Content.Collection.Count > 0 &&
                selectedIndex < item.Content.Collection.Count)
            {
                if (TabItemDesignModeValueProvider.GetDesignTimeIsSelected(item.Content.Collection[selectedIndex]))
                {
                    return(selectedIndex);
                }
            }
            return(-1);
        }
        /// <summary>
        /// Determine how the control is parented into the TabItem.
        /// If the control is a TabItem then parent it to the TabControl rather
        /// than the TabItem (think select, copy, paste a TabItem).
        /// If the TabItem has content and the content can accept children
        /// then parent into that and so on.
        /// </summary>
        /// <param name="parent">The parent item.</param>
        /// <param name="childType">The type of child item.</param>
        /// <returns>Redirected parent.</returns>
        public override ModelItem RedirectParent(ModelItem parent, Type childType)
        {
            _canParent = true;

            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (childType == null)
            {
                throw new ArgumentNullException("childType");
            }

            // if the tabItem is not activated and/or not within TabControl,
            // redirect to its parent by returning ourselves.
            if (parent.IsItemOfType(MyPlatformTypes.TabItem.TypeId) &&
                parent.Parent != null &&
                (!parent.Parent.IsItemOfType(MyPlatformTypes.TabControl.TypeId) || !TabItemDesignModeValueProvider.GetDesignTimeIsSelected(parent)))
            {
                _canParent = false;
                return(parent);
            }

            // if element being parented is tabItem then add it as sibling of
            // existing tabItems inside TabControl - redirect to parent;
            // else parent this control in TabItem's content, if its Panel.
            if (ModelFactory.ResolveType(parent.Context, MyPlatformTypes.TabItem.TypeId).IsAssignableFrom(childType))
            {
                _canParent = false;
                return(parent);
            }

            if (parent.Content != null && parent.Content.IsSet)
            {
                // if TabItem has a content and if the content is a panel or a contentcontrol,
                // let the content act as the parent.
                ModelItem content = parent.Content.Value;
                if (content != null)
                {
                    ViewItem contentView = content.View;
                    if (content.View != null)
                    {
                        // if the content is not visible but the tabItem is selected,
                        // Update this TabItems Layout.
                        if (!contentView.IsVisible && TabItemDesignModeValueProvider.GetDesignTimeIsSelected(parent))
                        {
                            parent.View.UpdateLayout();
                        }

                        if (contentView.IsVisible &&
                            (content.IsItemOfType(MyPlatformTypes.Panel.TypeId) || content.IsItemOfType(MyPlatformTypes.ContentControl.TypeId)))
                        {
                            return(content);
                        }
                    }
                    else
                    {
                        // TabItem has a content already but the content cannot accept parenting right now
                        // so let tabItem's parent take care of parenting.
                        _canParent = false;
                        return(parent);
                    }
                }
            }

            // TabItem doesnt have any content and now tabItem itself acts as the parent.
            return(base.RedirectParent(parent, childType));
        }