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 (wpf)
——————————————–

 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.

                    }

                }
, , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share to Facebook Share to Twitter Stumble It Share on Tumblr Digg More...