我正在尝试实现拖放功能来安排我的列表框的内容。我能够拖动该项目。当我尝试将第二个项目拖到第一个项目时,它出现在第一个项目上,但是当我尝试将第一个项目拖到第二个项目时,第一个项目位于第二个项目下。我也无法接住掉落,所以我可以安排物品。
有人可以帮我吗?
这是我正在使用的代码示例
<ListBox Name="lstBoxImages" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkits:WrapPanel
Width="450"
Height="Auto"
ItemWidth="225"
ItemHeight="Auto"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Source}" Height="200" Width="200" MouseMove="MouseMoving">
<i:Interaction.Behaviors>
<el:MouseDragElementBehavior ConstrainToParentBounds="False"/>
</i:Interaction.Behaviors>
</Image>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
后面的代码:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
List<ImageInfo> lstImages = new List<ImageInfo>();
lstImages.Add(new ImageInfo() { ImageID = 1, Source = "Images/4.png" });
lstImages.Add(new ImageInfo() { ImageID = 2, Source = "Images/2.png" });
lstImages.Add(new ImageInfo() { ImageID = 3, Source = "Images/4.png" });
lstImages.Add(new ImageInfo() { ImageID = 4, Source = "Images/2.png" });
lstImages.Add(new ImageInfo() { ImageID = 5, Source = "Images/4.png" });
lstImages.Add(new ImageInfo() { ImageID = 6, Source = "Images/2.png" });
lstBoxImages.ItemsSource = lstImages;
}
private void MouseMoving(object sender, System.Windows.Input.MouseEventArgs e)
{
Image realSender = (Image)sender;
int zIndex = Canvas.GetZIndex(realSender);
Canvas.SetZIndex(realSender, zIndex++);
}
我的信息类是:
public class ImageInfo
{
private int _ImageID;
private string _Source;
public string Source
{
get { return _Source; }
set { _Source = value; }
}
public int ImageID
{
get { return _ImageID; }
set { _ImageID = value; }
}
}
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:el="clr-namespace:Microsoft.Expression.Interactivity.Layout;assembly=Microsoft.Expression.Interactions"