Thursday, July 25, 2019

WPF - How to print Parent hierarchy of an element?



How to print Parent hierarchy of an element?

            DependencyObject _parent = myGrid.Parent;
            while (_parent != null)
            {
                System.Diagnostics.Debug.WriteLine(_parent);
                _parent = ((FrameworkElement)_parent)?.Parent;
            }

Every framework element has a Parent property, we can loop through like above code and print parent of particular element.

No comments:

Post a Comment

C# Record type: Something to remember while using record types

  Record in c# provide a concise and expressive way to create immutable data types, record is a keyword in c#, we can use this keyword with ...