private static void OnContentNamePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ContentLayout currentOwner = GetContainer(o);

            if (currentOwner != null)
            {
                currentOwner.OnContentNameChanged(o, (string)e.OldValue, (string)e.NewValue);
            }
        }
        private void OnContentListCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                UIElement content = (UIElement)e.NewItems[0];

                ContentLayout currentOwner = ContentLayout.GetContainer(content);
                if (currentOwner != null)
                {
                    currentOwner.ContentList.Remove(content);
                }

                ContentLayout.SetContainer(content, this);

                string contentName = ContentLayout.GetContentName(content);

                ContentPresenter contentPresenter = GetPresenter(contentName);
                if (contentPresenter != null)
                {
                    Grid grid = new Grid();
                    grid.Children.Add(content);

                    contentPresenter.Content = grid;
                    grid.UpdateLayout();
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                UIElement content = (UIElement)e.OldItems[0];

                string contentName = ContentLayout.GetContentName(content);

                ContentPresenter contentPresenter = GetPresenter(contentName);
                if (contentPresenter != null)
                {
                    contentPresenter.Content = null;
                }
            }
        }
        /// <internalonly />
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (_contentList.Count != 0)
            {
                Dispatcher.BeginInvoke(delegate() {
                    foreach (UIElement content in _contentList)
                    {
                        string contentName = ContentLayout.GetContentName(content);
                        ContentPresenter contentPresenter = GetPresenter(contentName);

                        if (contentPresenter != null)
                        {
                            Grid grid = new Grid();
                            grid.Children.Add(content);

                            contentPresenter.Content = grid;
                            grid.UpdateLayout();
                        }
                    }
                });
            }
        }
 internal static void SetContainer(DependencyObject o, ContentLayout value)
 {
     o.SetValue(ContainerProperty, value);
 }
 internal static void SetContainer(DependencyObject o, ContentLayout value)
 {
     o.SetValue(ContainerProperty, value);
 }