问题
I have Canvas binded with ObsarvableCollection:
<ItemsControl ItemsSource="{Binding Path=MapElements}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Width="{Binding ElementName=mapWidth, Path=Text}"
Height="{Binding ElementName=mapHeight, Path=Text}"
Background="WhiteSmoke"
AllowDrop="True"
Margin="10,10,10,10"
ClipToBounds="True"
Drop="Mapa_Drop_1"
DragOver="Mapa_DragOver_1"
DragEnter="Mapa_DragEnter_1"
Name="Mapa">
</Canvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Image}"
Margin="0,0,5,0" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Top"
Value="{Binding Y}" />
<Setter Property="Canvas.Left"
Value="{Binding X}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
I implemented drag and drop images into it. Everything works good but I want to add preview while dragging an object over canvas. I could just add an object to my observablecollection while dragging but what if somebody will not drop an object on canvas (it should be removed from my observablecollection). How can I implement this?
来源:https://stackoverflow.com/questions/14201198/wpf-drag-on-canvas-with-preview