ListBoxDragDropTarget :可以让它工作
我有一个 Silverlight 4 业务应用程序,我已于 2011 年 4 月安装了 Silverlight Toolkit 并添加了对该项目的引用。我想使用拖放对列表框重新排序。
我的代码如下:
<Grid x:Name="LayoutRoot">
<toolkit:ListBoxDragDropTarget AllowDrop="True">
<ListBox AllowDrop="True" Name="listBox1">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolkit:ListBoxDragDropTarget>
</Grid>
当
private void Page_Loaded(object sender, RoutedEventArgs e)
{
listBox1.ItemsSource = new Int32[] {1,2,3,4,5 };
}
尝试拖动一个项目时,我看到该项目的“幽灵”和一个带有两个箭头(一个向上和一个向下箭头)的图标,但是当我放下它(在同一个列表框中)时什么也没有发生!它不会被重新排序。
我做错了什么??? 我是否必须监听事件并实施某些操作?
谢谢!
编辑:完整的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
namespace editorencuestas
{
public partial class testdragdrop : Page
{
public testdragdrop()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
listBox1.ItemsSource = new Int32[] {1,2,3,4,5 };
}
}
}
AND
<navigation:Page x:Class="editorencuestas.testdragdrop"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="testdragdrop Page" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" Loaded="Page_Loaded">
<Grid x:Name="LayoutRoot">
<toolkit:ListBoxDragDropTarget AllowDrop="True">
<ListBox x:Name="listBox1" Height="175" Width="147">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolkit:ListBoxDragDropTarget>
</Grid>
</navigation:Page>
I have a Silverlight 4 Business Application, I've installed Silverlight Toolkit April 2011 and added the reference to the project. I want to to reorder a listbox using drag and drop.
My code is the following:
<Grid x:Name="LayoutRoot">
<toolkit:ListBoxDragDropTarget AllowDrop="True">
<ListBox AllowDrop="True" Name="listBox1">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolkit:ListBoxDragDropTarget>
</Grid>
And
private void Page_Loaded(object sender, RoutedEventArgs e)
{
listBox1.ItemsSource = new Int32[] {1,2,3,4,5 };
}
When trying to drag an item I see the "ghost" of the item and an icon whth two arrows (an up and a down arrow) but when I drop it (in the same listbox) nothing happens! It doesnt get reordered.
What am I doing wrong???
Do I have to listen to an event and implement something??
Thanks!
EDIT: The complete code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
namespace editorencuestas
{
public partial class testdragdrop : Page
{
public testdragdrop()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
listBox1.ItemsSource = new Int32[] {1,2,3,4,5 };
}
}
}
AND
<navigation:Page x:Class="editorencuestas.testdragdrop"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="testdragdrop Page" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" Loaded="Page_Loaded">
<Grid x:Name="LayoutRoot">
<toolkit:ListBoxDragDropTarget AllowDrop="True">
<ListBox x:Name="listBox1" Height="175" Width="147">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</toolkit:ListBoxDragDropTarget>
</Grid>
</navigation:Page>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以试试这个吗?
抱歉我错了。
如果你这样做,它就会起作用。
can you pls try this?
Sorry I was wrong.
If you do this it will work.