tags:

views:

114

answers:

2

Hi,

Is there a way to programatically go through a window's child elements to find one with a certain name? I'm loading xaml dynamically that creates a window and I'm looking to find a "placeholder" control inside it.

Thanks!

+2  A: 

Use the root control's FindName method.

Brandon
Because controls are added programatically don't forget to use RegisterName.http://social.msdn.microsoft.com/forums/en-US/wpf/thread/1faeed04-3adf-4324-9a1b-68ac4aca64bc
m1k4
Yep, this is a very important step thats usuaully overlooked. Simply giving it a name is not enough.
Brandon
Considering that my window is built through XamlReader.LoadAsync, I don't need to register anything. So FindName just works. Thanks!
Steve the Plant
A: 

Alternatively you can use

VisualTreeHelper

to enumerate down the tree of controls.

Wolf5