I am currently having a problem using MouseDragElementsBehavior from the Blend SDK when using ItemsControl and Custom Canvas. My custom canvas simply adds or removes MouseDragElement from its children, depending on DependencyProperty. This worked very well when I manually added items to the children of the Canvas, but it seemed to break when moving to the ItemsControl.
I am currently using the following ItemsControl code:
<ItemsControl ItemsSource="{Binding Path=CanvasItems}"> <ItemsControl.DataContext> <ViewModels:ViewModel/> </ItemsControl.DataContext> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <my:CustomCanvas Background="Black" IsEditable="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.CanEdit}" AllowDrop="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl>
Adding drag and drop behavior to the Canvas.VisualChildrenChanged method does not allow you to move the newly created object, as before.
Do I need to add Drag behavior to something other than ContentPresenter, which is passed in by VisualChildrenChanged or provides a special style?
source share