private Visual DisposeChildren(IRenderContext ctx, Visual removedVisual, bool dispose)
        {
            var container = removedVisual as VisualGroup;

            if (container != null && container.Children.Count > 0)
            {
                ctx.ChildVisualRemoved(container.Children[0]);
            }
            return(null);
        }
        /// <summary>
        /// Updates a visual which rotates the visualization of the wrapped style.
        /// </summary>
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, INode node)
        {
            var container = oldVisual as RotatableNodeStyleVisual;

            if (container == null || container.Children == null || container.Children.Count != 1)
            {
                return(CreateVisual(context, node));
            }

            var oldWrappedStyle = container.WrappedStyle;
            var newWrappedStyle = Wrapped;
            var creator         = newWrappedStyle.Renderer.GetVisualCreator(node, newWrappedStyle);

            IVisual oldWrappedVisual = container.Children[0];
            IVisual newWrappedVisual;

            if (newWrappedStyle != oldWrappedStyle)
            {
                newWrappedVisual = creator != null?creator.CreateVisual(context) : null;
            }
            else
            {
                newWrappedVisual = creator != null?creator.UpdateVisual(context, oldWrappedVisual) : null;
            }

            if (oldWrappedVisual != newWrappedVisual)
            {
                container.Children[0] = newWrappedVisual;
                context.ChildVisualRemoved(oldWrappedVisual);
            }
            context.RegisterForChildrenIfNecessary(oldVisual, DisposeChildren);

            var center = node.Layout.GetCenter();

            if (newWrappedStyle != oldWrappedStyle || container.Angle != Angle || !container.Center.Equals(center))
            {
                var rotation = container.Transform;
                rotation.Reset();
                rotation.RotateAt((float)-Angle, new PointF((float)center.X, (float)center.Y));
                container.WrappedStyle = newWrappedStyle;
                container.Center       = center;
                container.Angle        = -Angle;
            }

            return(container);
        }
        /// <summary>
        /// Updates a visual which rotates the visualization of the wrapped style.
        /// </summary>
        protected override VisualGroup UpdateVisual(IRenderContext context, VisualGroup oldVisual, INode node)
        {
            if (oldVisual.Children == null || oldVisual.Children.Count != 1)
            {
                return(CreateVisual(context, node));
            }

            var cache = oldVisual.GetRenderDataCache <RotateRenderData>();

            var oldWrappedStyle = cache.WrappedStyle;
            var newWrappedStyle = Wrapped;
            var creator         = newWrappedStyle.Renderer.GetVisualCreator(node, newWrappedStyle);

            Visual oldWrappedVisual = oldVisual.Children[0];
            Visual newWrappedVisual;

            if (newWrappedStyle != oldWrappedStyle)
            {
                newWrappedVisual = creator != null?creator.CreateVisual(context) : null;
            }
            else
            {
                newWrappedVisual = creator != null?creator.UpdateVisual(context, oldWrappedVisual) : null;
            }

            if (oldWrappedVisual != newWrappedVisual)
            {
                oldVisual.Children[0] = newWrappedVisual;
                context.ChildVisualRemoved(oldWrappedVisual);
            }
            context.RegisterForChildrenIfNecessary(oldVisual, DisposeChildren);

            var center = node.Layout.GetCenter();

            if (newWrappedStyle != oldWrappedStyle || cache.Angle != Angle || !cache.Center.Equals(center))
            {
                var transform = (RotateTransform)oldVisual.RenderTransform;
                transform.CenterX = center.X;
                transform.CenterY = center.Y;
                transform.Angle   = -Angle;
                oldVisual.SetRenderDataCache(new RotateRenderData(newWrappedStyle, Angle, center));
            }

            return(oldVisual);
        }