我用listbox绑定了photos(自定的类),想把listbox中的图片拖动到旁边的画布中。请高人指教。

解决方案 »

  1.   

    这是我的xaml 代码
    <Window x:Class="WpfDragDrop.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Drop and Drag" Height="800" Width="800">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>            <ColumnDefinition/>        </Grid.ColumnDefinitions>
            <DockPanel Name="_dockPanel" DataContext="{DynamicResource photos}" Background="Blue"   Width="160" Uid="5" AllowDrop="True" HorizontalAlignment="Left" Margin="0,0,0,22">            
                
                <ListBox x:Name="pictureBox" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.IsDeferredScrollingEnabled="True"   >
                    <ListBox.Resources>                    <Style TargetType="{x:Type ListBoxItem}">                        <!--<Setter Property="Width" Value="100"/>-->                                                <EventSetter Event="MouseLeftButtonDown" Handler="DragImage"/>                    </Style>                </ListBox.Resources>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Image Source="{Binding Path=FullPath}" Margin="5,8" Height="50">
                                <Image.LayoutTransform>
                                    <StaticResource ResourceKey="st" />
                                </Image.LayoutTransform>
                                <Image.ToolTip>
                                    <StackPanel>
                                        <TextBlock Text="{Binding Path=Name}" />
                                        <TextBlock Text="{Binding Path=DateTime}" />
                                    </StackPanel>
                                </Image.ToolTip>
                            </Image>
                        </DataTemplate>
                    </ListBox.ItemTemplate>                <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </DockPanel>        <Canvas  x:Name="Canvas1" Grid.Column="1"  AllowDrop="True" Margin="5"                Drop="DropImage">        </Canvas>    </Grid>
    </Window>
      

  2.   

    那位大侠出手相助,我可以把源代码呈上。留下你的Email。
      

  3.   

    解决没? [email protected]