-1

How Can I use this code in WPF:

foreach (Control c in this.Controls)
{

}

(I want to change opacity of elements one after another!)

amirhossein
  • 94
  • 2
  • 11

1 Answers1

0

WPF doesn't have the concept of controls the same way WinForms does.
You need to determine if it's a ContentControl or a Panel. ContentControl has Content of object and Panel has Children of UIElement.

Look at my answer on this question... I show how to cycle the controls and I explain it as well.

Link to Get all Controls with explanation

Michael Puckett II
  • 6,586
  • 5
  • 26
  • 46
  • 1
    @amirhossein What do you mean? That is a compiled working example that I posted. If you're not using C# 7 then I recommend you upgrade to use it... If not then you'll have to tweak it some for the C# version you're using. Other than the syntax it should work just fine. I've used this recursive type search for years in WPF. – Michael Puckett II Jun 16 '17 at 05:21
  • Not a problem. Glad to help. – Michael Puckett II Jun 16 '17 at 05:26