I have a control
class DragGrid : Grid { ... }
which inherits from the original grid and enables dragging and resizing its child elements.
I need to bind a custom DP named WorkItemsProperty
to an observable collection of type WorkItem
(implements INotifyPropertyChanged
). Each element in the grid is bound to a collection item.
Whenever the user adds a new item dynamically at runtime (the items cannot be declared in XAML!), or deletes an item from that collection, the WorkItems
DP on the DragGrid should be updated, and the children in the grid (where each child represents a WorkItem
collection item).
My question is how does the DP notify the control about which child element in the grid must be removed, changed ('change' means user dragged an element, or resized it with the mouse) or added, and how would I identify which one of the existing children is the one that needs to be deleted or changed.
I understand that this is where the DependencyPropertyChangedCallback comes in. But that only gets called when the DP property is set anew, not when something inside the collection changes (like add, remove item). So in the end, does the DragGrid
control somehow need to subscribe to the CollectionChanged event? At what point would I hook up the event handler for that?
EDIT:: The reason for using a Grid in the first place is because I want to be able to maintain a minimum delta for when the user drags or resizes the control in the Grid. A control represents a time span, and each grid column represents 15min (which is the minimum value). Doing this in a Canvas with Thumbs was difficult and buggy. Implementing a DragGrid solved my user interaction problems. Also, a Canvas is not scalable, so the time spans would have to recalculated all the time. With the Grid, I don't have the problem because the columns tell me the time no matter the size.*