private bool RemoveVisualElement(DesignSurfacePair <VisualElement> pair)
        {
            // we don't allow the root element to be removed.
            if (pair.XenWidget.Parent == null)
            {
                return(false);
            }

            var parentId   = pair.XenWidget.Parent.Id;
            var parentPair = this[parentId];

            if (parentPair == null)
            {
                return(false);
            }

            // this is the only child of the content page
            if (parentId == Root.Id)
            {
                var page = parentPair.VisualElement as ContentPage;
                if (page != null)
                {
                    page.Content = null;
                    return(true);
                }
            }

            // this maybe a layout control
            var viewContainer = parentPair.VisualElement as IViewContainer <View>;
            var childView     = pair.VisualElement as View;
            var parentView    = parentPair.VisualElement;

            // we can only remove view types; this shouldn't happen.
            if (childView == null)
            {
                return(false);
            }

            // is this a content property?
            if (viewContainer == null && ElementHelper.HasContentProperty(parentView))
            {
                ElementHelper.ClearContentProperty(parentView);
            }

            // is it a layout control? i.e. stacklayout, grid..
            if (viewContainer == null)
            {
                return(false);
            }

            // made it this far, it's a layout control.
            viewContainer.Children.Remove(childView);
            return(true);
        }
        protected override XenWidget BuildTree(VisualElement childView, XenWidget parentWidget)
        {
            /*
             *  1. Return parent widget if child view is null.
             *  Since, We won't be able to create a XenWidget out of the view.
             */

            if (childView == null)
            {
                return(parentWidget);
            }

            /*
             *  2. Create a XenWidget for the child view.
             */

            var childWidget = CreateXenWidget(childView, parentWidget);

            parentWidget.Children.Add(childWidget);

            if (ElementHelper.HasContentProperty(childView))
            {
                childWidget.AllowsManyChildren        = ElementHelper.ContentPropertyAllowsManyChildren(childView);
                childWidget.IsContentPropertyViewType = ElementHelper.IsContentPropertyView(childView);
                childWidget.ContentPropertyTypeName   = ElementHelper.GetContentPropertyTypeName(childView);
                childWidget.HasContentProperty        = true;
                childWidget.IsLayout = false;
            }
            else
            {
                childWidget.HasContentProperty = false;
            }

            /*
             *  3. Determine if the child view has children of it's own.
             */

            var isParentView = childView as ILayoutController;

            if (isParentView != null)
            {
                childWidget.IsLayout = true;
            }

            var grandchildren = isParentView?.Children;

            if (grandchildren == null || grandchildren.Count == 0)
            {
                return(parentWidget);
            }

            /*
             *  4. The child does have it's own children.
             */

            foreach (var grandchild in grandchildren)
            {
                var view = grandchild as View;

                if (view != null)
                {
                    if (view is ILayoutController)
                    {
                        BuildTree(view, childWidget);
                    }
                    else
                    {
                        var grandchildWidget = CreateXenWidget(view, childWidget);

                        if (ElementHelper.HasContentProperty(view))
                        {
                            grandchildWidget.IsLayout = true;
                        }

                        childWidget.Children.Add(grandchildWidget);
                    }
                }
            }

            return(parentWidget);
        }