Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF VB.NET
Hi,
 
Is there any way to find the control's actual name using Visual tree.
 
i.e let say I have a button called "Run Movie" on a canvas over WPF window "MovieWindow".
 
Using Window control in the Visual tree, I can trace button using below code.
 
dim myKid as DependencyObject = Nothing
for i as integer =0 to VisualTreeHelper.GetChildrenCount(MovieWindow) -1
  myKid = VisualTreeHelper.GetChild(MovieWindow,i)
 
  dim controlName as string = myKid.DependecyObjectType.Name
Next
 

In the above code controlName will get the name of the control as "Button".
 
How to get the button name as "Run Movie" using Visual tree.
 

Thanks in Advance.
Best Regards,
Posted 2-Dec-12 19:21pm
Edited 2-Dec-12 19:42pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Thanks guys for all your effort. I found out below solution.
 
We have to use control.GetValue(Control.NameProperty)
 
For Example, In the below code, by tracing mainWindow i.e MovieWindow, I will get Button.
 
To get the name of the Button, I should do
myKid.GetValue(Control.NameProperty)
 
This is by using dependecy property GetValue method().
(DependencyObject.GetValue(Control.nameProerty))
 
dim myKid as DependencyObject = Nothing
for i as integer =0 to VisualTreeHelper.GetChildrenCount(MovieWindow) -1
  myKid = VisualTreeHelper.GetChild(MovieWindow,i)
 
  dim controlName as string = myKid.DependecyObjectType.Name
Next
 

Best Regards,
 
Vijay
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid