I have too many textboxes and comboboxes in wpf form so i just want to know how to reset all the controls at once on a button click
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mageshwaran RPosted Nov 24, 2019, 11:27 AM
Shweta LodhaPosted Feb 9, 2016, 5:45 AM
Hi Shubha Kumar,
You have to iterate through all the visual elements in your form and then by checking the specific types (for you it is textbox and combobox), you can reset them. Code to get all the visual object is:
public static void EnumVisual(Visual parent, List<Visual> myCollection){
for (int iCount = 0; iCount < VisualTreeHelper.GetChildrenCount(parent); iCount ++)
{
// Get the child at mentioned index value.
Visual childVisualObject = (Visual)VisualTreeHelper.GetChild(parent, iCount);
// Add the child object to the your collection.
myCollection.Add(childVisualObject);
EnumVisual(childVisualObject, myCollection);
}}