Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF - Binding an ObservableCollection Dependency Property within a UserControl
    primarykey
    data
    text
    <p>I have a control</p> <blockquote> <p>class DragGrid : Grid { ... }</p> </blockquote> <p>which inherits from the original grid and enables dragging and resizing its child elements. I need to bind a custom DP named <strong><code>WorkItemsProperty</code></strong> to an observable collection of type <strong><code>WorkItem</code></strong> (implements <code>INotifyPropertyChanged</code>). Each element in the grid is bound to a collection item.</p> <p>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 <code>WorkItems</code> DP on the DragGrid should be updated, and the children in the grid (where each child represents a <code>WorkItem</code> collection item).</p> <p>My question is how does the DP notify the control about which child element in the grid must be <strong>removed</strong>, <strong>changed</strong> ('change' means user dragged an element, or resized it with the mouse) or <strong>added</strong>, 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 <code>DragGrid</code> control somehow need to subscribe to the CollectionChanged event? At what point would I hook up the event handler for that?</p> <p><strong>*EDIT::</strong> 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.**</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload