protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            this.AllowDrop = true;
            this.Content   = outerGrid;
            if (this.ItemsPanel != null)
            {
                this.panel.ItemsPanel = this.ItemsPanel;
            }

            ICompositeViewEvents containerEvents = null;
            bool isDefault = false;

            this.Loaded += (s, eventArgs) =>
            {
                isDefault           = this.IsDefaultContainer;
                selectedSpacerIndex = addAtEndMarker;
                DependencyObject parent = VisualTreeHelper.GetParent(this);
                while (null != parent && !typeof(ICompositeViewEvents).IsAssignableFrom(parent.GetType()))
                {
                    parent = VisualTreeHelper.GetParent(parent);
                }
                containerEvents = parent as ICompositeViewEvents;
                if (null != containerEvents)
                {
                    if (isDefault)
                    {
                        containerEvents.RegisterDefaultCompositeView(this);
                    }
                    else
                    {
                        containerEvents.RegisterCompositeView(this);
                    }
                }
                if (this.Items != null)
                {
                    //UnRegistering because of 137896: Inside tab control multiple Loaded events happen without an Unloaded event.
                    this.Items.CollectionChanged -= new NotifyCollectionChangedEventHandler(OnCollectionChanged);
                    this.Items.CollectionChanged += new NotifyCollectionChangedEventHandler(OnCollectionChanged);
                }
                if (populateOnLoad)
                {
                    this.PopulateContent();
                }
            };

            this.Unloaded += (s, eventArgs) =>
            {
                if (null != containerEvents)
                {
                    if (isDefault)
                    {
                        containerEvents.UnregisterDefaultCompositeView(this);
                    }
                    else
                    {
                        containerEvents.UnregisterCompositeView(this);
                    }
                }
                if (this.Items != null)
                {
                    this.Items.CollectionChanged -= new NotifyCollectionChangedEventHandler(OnCollectionChanged);
                }
                populateOnLoad = true;
            };
        }
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            this.AllowDrop = true;
            this.Content   = containerGrid;
            ICompositeViewEvents containerEvents = null;
            bool isDefault = false;

            this.Loaded += (s, eventArgs) =>
            {
                isDefault = this.IsDefaultContainer;
                DependencyObject parent = VisualTreeHelper.GetParent(this);
                while (null != parent && !typeof(ICompositeViewEvents).IsAssignableFrom(parent.GetType()))
                {
                    parent = VisualTreeHelper.GetParent(parent);
                }
                containerEvents = parent as ICompositeViewEvents;
                if (null != containerEvents)
                {
                    if (isDefault)
                    {
                        containerEvents.RegisterDefaultCompositeView(this);
                    }
                    else
                    {
                        containerEvents.RegisterCompositeView(this);
                    }
                }
                this.shouldSetFocus = true;

                if (this.AutoWrapInSequenceEnabled)
                {
                    // spacer and placer holder
                    this.spacerHelper = new SpacerHelper(this);
                }
            };

            this.Unloaded += (s, eventArgs) =>
            {
                if (null != containerEvents)
                {
                    if (isDefault)
                    {
                        containerEvents.UnregisterDefaultCompositeView(this);
                    }
                    else
                    {
                        containerEvents.UnregisterCompositeView(this);
                    }
                }
                this.shouldSetFocus = false;

                if (this.AutoWrapInSequenceEnabled)
                {
                    if (this.spacerHelper != null)
                    {
                        this.spacerHelper.Unload();
                        this.spacerHelper = null;
                    }
                }
            };
        }