I've got a window with some expanders in it. When you open a expander there is some information inside it.
What i need to do is to open all expanders with one button so everything inside them becomes visible. When everything is visible i want to print the full page.
This is my code for expanding all expanders now:
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
The lines i use to iterate through my controls:
foreach (Expander exp in FindVisualChildren<Expander>(printpage))
{
exp.IsExpanded = true;
}
Now to the point:
The code above works in most cases. The only problem i have is that sometimes there are some expanders WITHIN expanders. The parent expanders do expand when the above code executes, The child expanders however remain unexpanded.
I hope someone can teach me how to expand those child expanders too.
EDIT
I forgot to mention that the child-expanders are not direct childs of the main expanders..
They are children of children of children of the main expanders.
My controll-tree goes something like this:
-Stackpanel
---List item
-----Grid
-------Expander (Main expanders)
---------Grid
-----------Textblock
-------------Expander
So i need to expand all expanders in this tree.