Find child controls in wpf

In wpf can traverse through VisualTree using VisualTreeHelper class to find the controls. Here is the example to find all the checkboxes inside a control using VisualTreeHelper class. 

C# Code

		for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parentcontrol); i++)

                {

                    var checkBox = VisualTreeHelper.GetChild(parentControl, i) as CheckBox;

                    if (checkBox != null)

                    {

                        // do task for the checkbox.


                    }

                } 
blog comments powered by Disqus