Thursday, June 28, 2007

WPF: getting a data-bound data template and the items within it

I'm so happy to find out about Rich Strahl's post on how to get the items within a data template that is data-bound to, say, a list box.

It turns out the only way to get an item inside a data template is to programmatically go into the UI hierarchy of the template... not elegant at all!

1 comments:

Justin Chase said...

It's not the only way... For one thing if you have the collection the control is bound against you don't need to go into the control at all (which you should have). Also you can bind your objects to commands or events and get access to them as a result of that command or event firing. Also some controls will offer a "selected value" property to get the data object of currently selected items.

About Me