tags:

views:

25

answers:

1

Hi,

I currently have (in C# WPF) a listbox with each item containing controls, among them a button and a progressbar. Now what I want to do, is the following:

Button mybutton = (Button)sender;

I want to retrieve the progressbar that is in the same listboxitem as my sender button. How do I acces that control? Do I use the visualtreehelper?

Thanks in advance,

+1  A: 

err, did you manually retemplate the listboxitem?

if it is, i believe you're using a container(such as grid) to host the button and progressbar. If that so, i think you can cast the sender into the container and loop for the children till you find the progressbar. if it's static, you can also find it using the index of the children.

dnr3
Yep I did retemplate. Now I do have the container element (a grid indeed). What is the best way to go through the grid now? Visualtreehelper and then use an if statement or is there something better like a grid.getchild kind of thing?
internetmw
there is a children property in Grid which list all of the child, if somehow you know the index of the control then just use the Children[index] to get the control
dnr3