Silverlight 4 Checkbox column without underlying property in data source?
I was wondering if there is anyway to interact with any of the advanced controls, GridView, ListView, Form View... i开发者_如何学编程n a way where you can display a list of items and have a checkbox next to each item, but without having a Boolean property behind that checkbox in the data source?
More over how would you read it back? Meaning if there were some items with their checkbox checked and you saved a list of those, when editing the selection, how would you populate it back in the control (meaning bind all items, create the grid, whatever it is... and only "check" the items that were selected)?
/* EDIT */
This represents the following scenario: You have a meny-to-meny relationship between say events and participants. When creating the "participant" record, you want to register them for as many events as there are available... You want to display all events, but be able to select some of them at a time.
/* END EDIT */
Thanks, Martin
I'm assuming your DataSource is a Model (a DTO or other way to transfer data from the server to the client). If this is true, you can wrap your model in another object, that has a IsSelected property. You can then bind to a list of extended attributes. I've heard this described as Aspect Oriented Programming. When you load up the data from your service, loop through and create the extender, setting the IsSelected based on your criteria and passing in the model. Then bind the checkbox to the IsSelected property.
example:
public class ModelExtender<T>
{
public T Model;
private bool isSelected = false;
public bool IsSelected
{
get { return this.isSelected; }
set
{
this.isSelected = value;
this.RaisePropertyChanged("IsSelected");
}
}
public ModelExtender(T model)
{
this.Model = model;
}
精彩评论