I need to specify Canvas as a panel for elements and connect the ability to move elements in it.
There is such a markup.
<ItemsControl ItemsSource="{Binding MapObjects}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas IsItemsHost="True"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <ContentControl Content="{Binding}"> <i:Interaction.Behaviors> <behaviors:DragBehavior/> </i:Interaction.Behaviors> </ContentControl> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemContainerStyle> <Style TargetType="ContentPresenter"> <Setter Property="Canvas.Left" Value="{Binding Position.X}"/> <Setter Property="Canvas.Top" Value="{Binding Position.Y}"/> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl> From the markup it can be seen that in order to be bound to the Canvas.Top/Left attachment properties, Canvas.Top/Left necessary to do a binding through the ContentPresenter style, because each element is wrapped in a ContentPresenter . But I can’t specify Behaviors through styles, because the designer swears by such a foul language
The Behaviors property is not a DependencyProperty
I tried to do so
<Setter Property="i:Interaction.Behaviors"> <Setter.Value> <behaviors:DragBehavior/> </Setter.Value> </Setter> And in the form in which it is now, it does not work, because the AssociatedObject in the DragBehavior code is ContentControl . Of course, I can find the element I need from the visual tree, but something tells me that there is a more elegant way that will not be so rigidly tied to the markup