WPF drag on canvas with preview

那年仲夏 提交于 2019-12-13 05:18:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!