Skip to main content
Home Forums General Silverlight Installation and Setup How to find control by type??
3 replies. Latest Post by addanki on June 17, 2009.
(0)
addanki
Member
16 points
46 Posts
06-17-2009 1:19 AM |
It is possible to find the control by name, as below.
UserControl
Button
My problem is, is it possible to find the control by type??
Button btn = ctrl.FindControl("Button") as Button;
if more than one button control is there, then it should return the ButtonList or it should be possible to set the starting index to search for the control.
Please let me know the approach to do in the above manner?
ksleung
Contributor
5366 points
1,028 Posts
06-17-2009 1:27 AM |
Don't know if there is a shorter answer but you can use VisualTreeHelper to (recursively) traverse the descendents of the user control, and test whether a descendent control is a Button...
if (control is Button) { do_something(control); }
06-17-2009 2:30 AM |
Hi,
Thanks for your quick reply.
I am able retrieve the descendents, but, after adding to the page, only button is visible, but the rest of the controls like TextBlock, TextBox which are there inside the XAML string are not visible?
Any idea what might be the mistake??
06-17-2009 2:53 AM |
I got my mistake..
Thanks
Ashok