![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | how to list controls present on the Winfx window Hi I want to list the controls available on the winfx form. I m using the following code for that foreach(Control c in Content) { String str = c.Name.ToString(); MessageBox.Show(str); } But its giving the following error.. "foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator' " Pls help me out to solve the problem.. Or how can approach to list the control...available on WPf forms... thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: how to list controls present on the Winfx window sam wrote: > Hi > I want to list the controls available on the winfx form. > I m using the following code for that > foreach(Control c in Content) > { > String str = c.Name.ToString(); > MessageBox.Show(str); > } > But its giving the following error.. > > "foreach statement cannot operate on variables of type 'object' > because 'object' does not contain a public definition for > 'GetEnumerator' " > > Pls help me out to solve the problem.. > Or how can approach to list the control...available on WPf forms... > thanks You want to use the VisualTreeHelper class... Content is indeed of type 'object' and cannot be enumerated... however, your content is bound to be represented by UIElements. What I suggest you do is to use the VisualTreeHelper.GetChildrenCount() and VisualTreeHelper.GetChild() methods and "recurse" into the visual tree of your ContentControl. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: how to list controls present on the Winfx window Hi Thanks for replying... i tried that and got the result But by using this class i m getting the list of control types...but i want to get particular control by its name .... i m not getting any property for that... pls help me put... Thanks... Marcus wrote: > sam wrote: > > Hi > > I want to list the controls available on the winfx form. > > I m using the following code for that > > foreach(Control c in Content) > > { > > String str = c.Name.ToString(); > > MessageBox.Show(str); > > } > > But its giving the following error.. > > > > "foreach statement cannot operate on variables of type 'object' > > because 'object' does not contain a public definition for > > 'GetEnumerator' " > > > > Pls help me out to solve the problem.. > > Or how can approach to list the control...available on WPf forms... > > thanks > > You want to use the VisualTreeHelper class... > > Content is indeed of type 'object' and cannot be enumerated... however, > your content is bound to be represented by UIElements. > > What I suggest you do is to use the VisualTreeHelper.GetChildrenCount() > and VisualTreeHelper.GetChild() methods and "recurse" into the visual > tree of your ContentControl. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: how to list controls present on the Winfx window You can try using the FindName() method obtained from the FrameworkElement class. But this will resolve only in the current namescope of the object you are calling the function on... There is also the protected internal method GetTemplateChild() that can do somehoe the same job, but Microsoft indicates that you better use FindName() instead. If FindName() / GetTemplateChild() still doesn't do it for you, you can try accessing the "Name" property obtained from the FrameworkElement class to access the element's name using the method I posted last time, that is bound to work! Sorry if I did not understand your original problem at first! Hope this will solve your issue... sam wrote: > Hi > Thanks for replying... > i tried that and got the result But by using this class i m getting the > list of control types...but i want to get particular control by its > name .... i m not getting any property for that... > pls help me put... > Thanks... > > Marcus wrote: > > > sam wrote: > > > Hi > > > I want to list the controls available on the winfx form. > > > I m using the following code for that > > > foreach(Control c in Content) > > > { > > > String str = c.Name.ToString(); > > > MessageBox.Show(str); > > > } > > > But its giving the following error.. > > > > > > "foreach statement cannot operate on variables of type 'object' > > > because 'object' does not contain a public definition for > > > 'GetEnumerator' " > > > > > > Pls help me out to solve the problem.. > > > Or how can approach to list the control...available on WPf forms... > > > thanks > > > > You want to use the VisualTreeHelper class... > > > > Content is indeed of type 'object' and cannot be enumerated... however, > > your content is bound to be represented by UIElements. > > > > What I suggest you do is to use the VisualTreeHelper.GetChildrenCount() > > and VisualTreeHelper.GetChild() methods and "recurse" into the visual > > tree of your ContentControl. |
My System Specs![]() |
| | #5 (permalink) |
| | Re: how to list controls present on the Winfx window Hi.. I got it. I tried that with Visualtreehelper class...Dependency property (name property). Thanksī Marcus wrote: > You can try using the FindName() method obtained from the > FrameworkElement class. But this will resolve only in the current > namescope of the object you are calling the function on... > > There is also the protected internal method GetTemplateChild() that can > do somehoe the same job, but Microsoft indicates that you better use > FindName() instead. > > If FindName() / GetTemplateChild() still doesn't do it for you, you can > try accessing the "Name" property obtained from the FrameworkElement > class to access the element's name using the method I posted last time, > that is bound to work! > > Sorry if I did not understand your original problem at first! > > Hope this will solve your issue... > > sam wrote: > > Hi > > Thanks for replying... > > i tried that and got the result But by using this class i m getting the > > list of control types...but i want to get particular control by its > > name .... i m not getting any property for that... > > pls help me put... > > Thanks... > > > > Marcus wrote: > > > > > sam wrote: > > > > Hi > > > > I want to list the controls available on the winfx form. > > > > I m using the following code for that > > > > foreach(Control c in Content) > > > > { > > > > String str = c.Name.ToString(); > > > > MessageBox.Show(str); > > > > } > > > > But its giving the following error.. > > > > > > > > "foreach statement cannot operate on variables of type 'object' > > > > because 'object' does not contain a public definition for > > > > 'GetEnumerator' " > > > > > > > > Pls help me out to solve the problem.. > > > > Or how can approach to list the control...available on WPf forms... > > > > thanks > > > > > > You want to use the VisualTreeHelper class... > > > > > > Content is indeed of type 'object' and cannot be enumerated... however, > > > your content is bound to be represented by UIElements. > > > > > > What I suggest you do is to use the VisualTreeHelper.GetChildrenCount() > > > and VisualTreeHelper.GetChild() methods and "recurse" into the visual > > > tree of your ContentControl. |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Checking a list and adding item if not present | PowerShell | |||