Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - how to list controls present on the Winfx window

 
 
Old 05-31-2006   #1 (permalink)
sam


 
 

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 SpecsSystem Spec
Old 05-31-2006   #2 (permalink)
Marcus


 
 

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 SpecsSystem Spec
Old 06-02-2006   #3 (permalink)
sam


 
 

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 SpecsSystem Spec
Old 06-02-2006   #4 (permalink)
Marcus


 
 

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 SpecsSystem Spec
Old 06-03-2006   #5 (permalink)
sam


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Checking a list and adding item if not present PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Š Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46