0

我将 Canvas 与 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>

我实现了将图像拖放到其中。一切正常,但我想在画布上拖动对象时添加预览。我可以在拖动时向我的 observablecollection 添加一个对象,但是如果有人不会将对象放在画布上怎么办(它应该从我的 observablecollection 中删除)。我该如何实施?

4

0 回答 0