I found this solution using MouseDragElementBehavior with ItemsControl and Canvas by JΓΆrg Reichardt. But this does not work for me.
This is my code:
<ItemsControl ItemsSource="{Binding CardCollection}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas Background="White" AllowDrop="True" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ContentControl Content="{Binding}"> <i:Interaction.Behaviors> <is:MouseDragElementBehavior ConstrainToParentBounds="True" /> </i:Interaction.Behaviors> </ContentControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
Elements are displayed on the canvas, but they cannot be dragged or deleted. I create new elements for cardCollection in the viewmodel, and cardCollection is updated to the model via mvvm propertynotifychanged.
source share