Binding editable children to something other than a list/grid control in WPF?

Binding editable children to something other than a list/grid control in WPF?

Old forum URL: forums.lhotka.net/forums/t/10503.aspx


TSF posted on Thursday, July 07, 2011

All the examples I've seen with parent/child relationships show the child objects being bound to controls such as a list view?  Is it possible to bind editable child objects to a "details form" instead of a list control?  If so, how do you tell the UI to bind to one specific editable child within the collection? Thanks.

RockfordLhotka replied on Thursday, July 07, 2011

In what UI technology?

TSF replied on Thursday, July 07, 2011

WPF.  Sorry - I had it the subject line but didn't put it in the description.

RockfordLhotka replied on Thursday, July 07, 2011

In XAML (WPF/SL/WP) you do need to have some way to select the current child object in the collection. But past that the binding is pretty much automatic.

Normally the source object (your collection) is managed by a CollectionViewSource object (often this is the resource in the XAML). The CVS manages currency, so it knows which item is current. By default, detail controls (like a TextBox) bound to the CVS will bind to the properties of the current item.

List controls (like a ListBox) bind to the CVS and display the entire list. But most list controls still use the CVS to track currency so the selected item in the control is also the current item in the CVS.

This makes it easy to create a screen with a ListBox down one side, and when the user clicks an item in the list, the detail controls on the other side of the form display the detail of the selected item - all by having the controls bind to the same CVS resource.

TSF replied on Thursday, July 07, 2011

Thanks. That makes sense.  It was also just brought to my attention that I could use the Editable Root List Parent stereotype, which contains a stub for an editable child (or multiple editable children) as properties of that editable root.  In my current scenario, I will always have a fixed number of editable children (five - corresponding to the 5 business days in a week).

Copyright (c) Marimer LLC