我正在尝试实施拖放功能来安排列表框的内容。我能够拖动该项目。当我尝试将第二个项目拖动到第一个项目时,它会显示在第一个项目上,但是当我尝试将第一个项目拖动到第二个项目时,则第一个项目会转到第二个项目下面。我也无法抓住掉落,所以我可以安排这些物品。
有人可以帮我吗?
这是我正在使用的代码示例
<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"
答案 0 :(得分:1)
您可以尝试从Bewise phone controls工具包中控制可订购列表 来自Telerik RadControls for Windows Phone的DataBoundListBox也支持重新排序的项目。