Click here to Skip to main content
15,878,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have listview with grouping under an expander. The items are dynamically generated. I can Access all the expanders in window control and save their state. Afterwards the item source property of listview is changed. Now if I try to get expanders or any other UI control, the function always returns null. The function is given below



public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject<br />
        {<br />
            if (depObj != null)<br />
            {<br />
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)<br />
                {<br />
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i);<br />
                    if (child != null && child is T)<br />
                    {<br />
                        yield return (T)child;<br />
                    }<br />
<br />
                    foreach (T childOfChild in FindVisualChildren<T>(child))<br />
                    {<br />
                        yield return childOfChild;<br />
                    }<br />
                }<br />
            }<br />
        }


What I have tried:

I have tried using several other functions but to no avail.
Posted
Updated 7-Sep-18 1:53am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900