Windows Presentation Foundation (WPF) Question:

Download Job Interview Questions and Answers PDF

How can I enumerate all the descendants of a visual object?

WPF Interview Question
WPF Interview Question

Answer:

You can enumerate all the descendants of a visual object as follows :

[C#]

// Enumerate all the descendants of the visual object.
static public void EnumVisual(Visual myVisual)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
{
// Retrieve child visual at specified index value.
Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

// Do processing of the child visual object.

// Enumerate children of the child visual object.
EnumVisual(childVisual);
}
}

Download WPF Interview Questions And Answers PDF

Previous QuestionNext Question
What is XAML extensible markup language?How can I create Custom Read-Only Dependency Properties?