/// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb = sb ?? new StringBuilder();

            Inner(viewGroup, spacing);
            return(sb.ToString());

            void Inner(ViewGroup vg, string s)
            {
                AppendView(vg, s);
                s += "  ";
                for (var i = 0; i < vg.ChildCount; i++)
                {
                    var child = vg.GetChildAt(i);
                    if (child is ViewGroup childViewGroup)
                    {
                        Inner(childViewGroup, s);
                    }
                    else
                    {
                        AppendView(child, s);
                    }
                }
            }

            void AppendView(View innerView, string s)
            {
                var name     = (innerView as IFrameworkElement)?.Name;
                var namePart = string.IsNullOrEmpty(name) ? "" : $"-'{name}'";

                var fe = innerView as IFrameworkElement;
                var u  = innerView as UIElement;
                var vg = innerView as ViewGroup;

                sb
                .Append(s)
                .Append(innerView == viewOfInterest ? "*>" : ">")
                .Append(innerView.ToString() + namePart)
                .Append($"-({ViewHelper.PhysicalToLogicalPixels(innerView.Width)}x{ViewHelper.PhysicalToLogicalPixels(innerView.Height)})@({ViewHelper.PhysicalToLogicalPixels(innerView.Left)},{ViewHelper.PhysicalToLogicalPixels(innerView.Top)})")
                .Append($"  {innerView.Visibility}")
                .Append(fe != null ? $" HA={fe.HorizontalAlignment},VA={fe.VerticalAlignment}" : "")
                .Append(fe != null && fe.Margin != default ? $" Margin={fe.Margin}" : "")
                .Append(fe != null && fe.TryGetBorderThickness(out var b) && b != default ? $" Border={b}" : "")
                .Append(fe != null && fe.TryGetPadding(out var p) && p != default ? $" Padding={p}" : "")
                .Append(u != null ? $" DesiredSize={u.DesiredSize}" : "")
                .Append(u != null && u.NeedsClipToSlot ? "CLIPPED_TO_SLOT" : "")
                .Append(u != null && u.RenderTransform != null ? $"RENDER_TRANSFORM({u.RenderTransform.MatrixCore})" : "")
                .Append(u?.Clip != null ? $" Clip={u.Clip.Rect}" : "")
                .Append(u == null && vg != null ? $" ClipChildren={vg.ClipChildren}" : "")
                .AppendLine();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb = sb ?? new StringBuilder();
            AppendView(viewGroup);
            spacing += "  ";
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);
                if (child is ViewGroup childViewGroup)
                {
                    ShowDescendants(childViewGroup, sb, spacing, viewOfInterest);
                }
                else
                {
                    AppendView(child);
                }
            }

            return(sb.ToString());

            StringBuilder AppendView(View innerView)
            {
                var name     = (innerView as IFrameworkElement)?.Name;
                var namePart = string.IsNullOrEmpty(name) ? "" : $"-'{name}'";

                var fe = innerView as IFrameworkElement;
                var u  = innerView as UIElement;
                var vg = innerView as ViewGroup;

                return(sb
                       .Append(spacing)
                       .Append(innerView == viewOfInterest ? "*>" : ">")
                       .Append(innerView.ToString() + namePart)
                       .Append($"-({ViewHelper.PhysicalToLogicalPixels(innerView.Width)}x{ViewHelper.PhysicalToLogicalPixels(innerView.Height)})@({ViewHelper.PhysicalToLogicalPixels(innerView.Left)},{ViewHelper.PhysicalToLogicalPixels(innerView.Top)})")
                       .Append($"  {innerView.Visibility}")
                       .Append(fe != null ? $" HA={fe.HorizontalAlignment},VA={fe.VerticalAlignment}" : "")
                       .Append(fe != null && fe.Margin != default(Thickness) ? $" Margin={fe.Margin}" : "")
                       .Append(fe != null && fe.GetPadding() is Thickness p && p != default(Thickness) ? $" Padding={p}" : "")
                       .Append(u != null ? $" DesiredSize={u.DesiredSize}" : "")
                       .Append(u?.Clip != null ? $" Clip={u.Clip.Rect}" : "")
                       .Append(u != null ? $" NeedsClipToSlot={u.NeedsClipToSlot}" : "")
                       .Append(u == null && vg != null ? $" ClipChildren={vg.ClipChildren}" : "")
                       .AppendLine());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb = sb ?? new StringBuilder();
            AppendView(viewGroup);
            spacing += "  ";
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);
                if (child is ViewGroup childViewGroup)
                {
                    ShowDescendants(childViewGroup, sb, spacing, viewOfInterest);
                }
                else
                {
                    AppendView(child);
                }
            }

            return(sb.ToString());

            void AppendView(View view)
            {
                sb.AppendLine($"{spacing}{(view == viewOfInterest ? "*" : "")}>{view.ToString()}-({ViewHelper.PhysicalToLogicalPixels(view.Width)}x{ViewHelper.PhysicalToLogicalPixels(view.Height)})");
            }
        }
Beispiel #4
0
        internal static Rect GetBoundsRectRelativeTo(this View element, View relativeTo)
        {
            var elementToTarget        = UIElement.TransformToVisual(element, relativeTo);
            var elementRect            = new Rect(0, 0, ViewHelper.PhysicalToLogicalPixels(element.Width), ViewHelper.PhysicalToLogicalPixels(element.Height));
            var elementRectRelToTarget = elementToTarget.TransformBounds(elementRect);

            return(elementRectRelToTarget);
        }
Beispiel #5
0
        /// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb = sb ?? new StringBuilder();
            AppendView(viewGroup);
            spacing += "  ";
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);
                if (child is ViewGroup childViewGroup)
                {
                    ShowDescendants(childViewGroup, sb, spacing, viewOfInterest);
                }
                else
                {
                    AppendView(child);
                }
            }

            return(sb.ToString());

            StringBuilder AppendView(View innerView)
            {
                var name     = (innerView as IFrameworkElement)?.Name;
                var namePart = string.IsNullOrEmpty(name) ? "" : $"-'{name}'";

                return(sb
                       .Append(spacing)
                       .Append(innerView == viewOfInterest ? "*>" : ">")
                       .Append(innerView.ToString() + namePart)
                       .Append($"-({ViewHelper.PhysicalToLogicalPixels(innerView.Width)}x{ViewHelper.PhysicalToLogicalPixels(innerView.Height)})")
                       .Append($"  {innerView.Visibility}")
                       .AppendLine());
            }
        }
        /// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb ??= new StringBuilder();

            Inner(viewGroup, spacing);
            return(sb.ToString());

            void Inner(ViewGroup vg, string s)
            {
                AppendView(vg, s);
                s += "  ";
                for (var i = 0; i < vg.ChildCount; i++)
                {
                    var child = vg.GetChildAt(i);
                    if (child is ViewGroup childViewGroup)
                    {
                        Inner(childViewGroup, s);
                    }
                    else
                    {
                        AppendView(child, s);
                    }
                }
            }

            void AppendView(View innerView, string s)
            {
                var name     = (innerView as IFrameworkElement)?.Name;
                var namePart = string.IsNullOrEmpty(name) ? "" : $"-'{name}'";

                var fe = innerView as IFrameworkElement;
                var u  = innerView as UIElement;
                var vg = innerView as ViewGroup;

                sb
                .Append(s)
                .Append(innerView == viewOfInterest ? "*>" : ">")
                .Append(innerView.ToString() + namePart)
                .Append($"-({ViewHelper.PhysicalToLogicalPixels(innerView.Width):F1}x{ViewHelper.PhysicalToLogicalPixels(innerView.Height):F1})@({ViewHelper.PhysicalToLogicalPixels(innerView.Left):F1},{ViewHelper.PhysicalToLogicalPixels(innerView.Top):F1})")
                .Append($"  {innerView.Visibility}")
                .Append(fe != null ? $" HA={fe.HorizontalAlignment},VA={fe.VerticalAlignment}" : "")
                .Append(fe != null && (!double.IsNaN(fe.Width) || !double.IsNaN(fe.Height)) ? $"FE.Width={fe.Width},FE.Height={fe.Height}" : "")
                .Append(fe != null && fe.Margin != default ? $" Margin={fe.Margin}" : "")
                .Append(fe != null && fe.TryGetBorderThickness(out var b) && b != default ? $" Border={b}" : "")
                .Append(fe != null && fe.TryGetPadding(out var p) && p != default ? $" Padding={p}" : "")
                .Append(u != null ? $" DesiredSize={u.DesiredSize.ToString("F1")}" : "")
                .Append(u != null && u.NeedsClipToSlot ? " CLIPPED_TO_SLOT" : "")
                .Append(u?.Clip != null ? $" Clip={u.Clip.Rect}" : "")
                .Append(u == null && vg != null ? $" ClipChildren={vg.ClipChildren}" : "")
                .Append(fe?.Background != null ? $" Background={fe.Background}" : "")
                .Append(u?.GetElementSpecificDetails())
                .Append(u?.GetElementGridOrCanvasDetails())
                .Append(u?.RenderTransform.GetTransformDetails())
                .Append($" IsLayoutRequested={innerView.IsLayoutRequested}")
                .Append(innerView is TextBlock textBlock ? $" Text=\"{textBlock.Text}\"" : "")
                .AppendLine();
            }
        }