在 Windows Phone 中拖放 [英] drag and drop in windows phone
问题描述
我正在尝试实现拖放功能来排列我的列表框的内容.我能够拖动该项目.当我尝试将第二个项目拖到第一个项目时,它出现在第一个项目上,但是当我尝试将第一个项目拖到第二个项目时,第一个项目位于第二个项目下方.也赶不上落下的东西,这样我就可以安排物品了.
i am trying to implement drag and drop feature to arrange the content of my listbox. I was able to drag the item. when i try to drag the second item to first item, it appears over the first item but when i try to drag the first item to second item, then first item goes under the second item. also i am unable to catch the drop, so that i can arrange the items.
有人可以帮我吗?
这是我正在使用的代码示例
here is the sample of code i am using
<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"
推荐答案
您可以尝试从 Bewise phone controls 工具包.
还有来自 Telerik RadControls for Windows Phone 的 DataBoundListBox支持物品重新排序.
You can try control Orderable List from Bewise phone controls toolkit.
Also DataBoundListBox from Telerik RadControls for Windows Phone also supports items reordering.
这篇关于在 Windows Phone 中拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!