Gabriel Magana
Gabriel Magana

Reputation: 4536

WPF bind to a list

I have a user control whose users I want to have them set a DataContext on to bind to a list of objects. In my control, however, I want to display that list in a Grid, but in a non-trivial order. The column/row of display of each element will be determined by some code I will write.

So I cannot do a straight databinding in my control, I need to write code that will read the DataContext and then do the processing to correctly position each element.

How would a relative WPF newbie go about doing that? I guess the part I don't understand is what the code in my usercontrol will look like to read the DataContext items so that I can process them.

EDIT: Clarification: I want to stress I want to bind to the XAML Grid element, not some other kind of grid or DataGrid. Thx!

Upvotes: 1

Views: 265

Answers (1)

japf
japf

Reputation: 6728

One of the possible way to achieve that is to use a Converter. You could create a Converter which converts the input list into another list where the order has been changed. Then you could use a "normal" databinding which will use the Converter.

Upvotes: 3

Related Questions