What techniques can I employ to create a series of UI Elements from a collection of objects using WP

Posted by elggarc on Stack Overflow See other posts from Stack Overflow or by elggarc
Published on 2010-03-25T17:03:45Z Indexed on 2010/03/25 22:33 UTC
Read the original article Hit count: 179

Filed under:

I'm new to WPF and before I dive in solving a problem in completely the wrong way I was wondering if WPF is clever enough to handle something for me.

Imagine I have a collection containing objects. Each object is of the same known type and has two parameters. Name (a string) and Picked (a boolean).

The collection will be populated at run time.

I would like to build up a UI element at run time that will represent this collection as a series of checkboxes. I want the Picked parameter of any given object in the collection updated if the user changes the selected state of the checkbox.

To me, the answer is simple. I iterate accross the collection and create a new checkbox for each object, dynamically wiring up a ValueChanged event to capture when Picked should be changed.

It has occured to me, however, that I may be able to harness some unknown feature of WPF to do this better (or "properly"). For example, could data binding be employed here?

I would be very interested in anyone's thoughts.

Thanks,

E

FootNote: The structure of the collection can be changed completely to better fit any chosen solution but ultimately I will always start from, and end with, some list of string and boolean pairs.

© Stack Overflow or respective owner

Related posts about wpf