Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine WPF element type

Tags:

c#

wpf

How to determine the element type in WPF programatically?

For example my xaml is consisting of textbox, radio buttons, combo's, list boxes etc.

In the load event, say I want to do something related to the controls.(Say for all textbox,

the foreground color will be red, for all labels the background color will be green)..

something of that sort.

So I have to loop through the entire list of controls present in the Xaml and then have to

write the control specific logic.

Is it by using Framework element?

Please give the code in c#. For example please take 3/4 controls of your choice.

I am also searching in google!

Thanks in advance

like image 576
priyanka.sarkar Avatar asked Jun 18 '26 17:06

priyanka.sarkar


1 Answers

You can use:

if (element is Grid)
{
}
else if (element is Label)
...

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!