我有一个包含图片<Image Source="{Binding Path=Image}" Width="56" Height="61"/>
的列表框和一个拖放事件。是否可以做这样的事情:例如,当我在矩形上删除所选项目时,此项目中的图像会弹出此矩形?
<WrapPanel
Name="WeaponPanel" Style="{StaticResource Panel}">
<ListBox x:Name="listweapons" Height="214" Width="248" ItemsSource="{Binding ListWeapon}"
IsSynchronizedWithCurrentItem="True" Canvas.Left="211" Canvas.Top="72"
PreviewMouseLeftButtonDown="weapons_PreviewMouseLeftButtonDown" DragLeave="weapons_DragLeave"
PreviewMouseMove="weapons_PreviewMouseMove" SelectedValuePath="attack">
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=Image}" Width="56" Height="61"/>
<TextBox Height="30" Width="30">
<Binding Path="_attack" />
</TextBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
private void helmet_MouseDown1(object sender, MouseButtonEventArgs e)
{
_startPoint = e.GetPosition(null);
}
private void helmet_PreviewMouseMove(object sender, MouseEventArgs e)
{
Point mousePos = e.GetPosition(null);
Vector diff = _startPoint - mousePos;
if (e.LeftButton == MouseButtonState.Pressed &&
(Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
{
var listBox = sender as ListBox;
var listBoxItem = listBox.SelectedItem;
DataObject dragData = new DataObject(_dropIdentifier, listBoxItem);
DragDrop.DoDragDrop(listBox, dragData, DragDropEffects.Move);
}
private void Rectangle_Drop_1(object sender, System.Windows.DragEventArgs e)
{
((Rectangle)sender).Fill = new SolidColorBrush(Color.FromRgb(14, 14, 14));
}