Link to home
Start Free TrialLog in
Avatar of Member_2_99151
Member_2_99151

asked on

How can I find a UIElement on a WPF application

Hi,

I have a number of Ellipses on the main interface to a WPF application.

I would like to change the properties of these programmatically, but I want to reference them by name (otherwise the code will be huge!!)

I would like something like this:

   
Ellipse mine = (Ellipse) UIElements.Find["ellipse12"];

Open in new window


I know this is not the correct syntax, but is this approach possible???

Any help would be appreciated.

Best regards,

James
Avatar of Silverlay
Silverlay

You can archive that by making your own wrap over VisualTreeHelper class in Silverlight.

Helpfull links on that class that have some use ready links:
http://blogs.msdn.com/b/kmahone/archive/2009/03/29/visualtreehelper.aspx
http://amyokabir.wordpress.com/2010/03/01/my-visualtreehelper-search-the-visual-tree/
Avatar of Member_2_99151

ASKER

Hi,

Thanks for the info..
I have found that the following does this directly...

    Int32 xElipseID = 3;
    Ellipse myEllipse = (Ellipse) FindName("ellipse" + xElipseID.ToString());

Is this *correct* WPF coding ?

James
ASKER CERTIFIED SOLUTION
Avatar of Silverlay
Silverlay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hee hee - point taken :-) Thanks