我已将所有数据绑定到RadTreeView
但无法使用拖放。我使用了四个属性作为
IsDragDropEnabled="True"
IsDropPreviewLineEnabled="True"
AllowDrop="True"
IsDragPreviewEnabled="True"
我想在同一棵树中删除一个项目。但它不起作用。
我已将所有数据绑定到RadTreeView
但无法使用拖放。我使用了四个属性作为
IsDragDropEnabled="True"
IsDropPreviewLineEnabled="True"
AllowDrop="True"
IsDragPreviewEnabled="True"
我想在同一棵树中删除一个项目。但它不起作用。
快速阅读这篇telerik 文章后,拖放似乎对我来说效果很好。
<telerik:RadTreeView ... EnableDragAndDrop="true" OnNodeDrop="MyTreeView_NodeDrop">
EnableDragAndDrop 和 OnNodeDrop 似乎是让它工作的两个重要部分,但不在您尝试的属性列表中。高温高压
<telerik:RadTreeView x:Name="treeView1" IsDragDropEnabled="True" Margin="2,0,0,0" ItemsSource="{Binding SelectedSectionList, Mode=TwoWay}" ItemTemplate="{StaticResource SectionTemplate}" IsEditable="True" SelectedItem="{Binding SelectedCustomSectionList, Mode=TwoWay}" Grid.Column="2">
现在在后面的代码中
你必须触发事件
在构造函数中
this.treeView1.AddHandler(RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnDropQuery), true);
然后
private void OnDropQuery(object sender, DragDropQueryEventArgs e)
{
RadTreeViewItem destinationItem = e.Options.Destination as RadTreeViewItem;
object source = this.GetItemFromPayload<object>(e.Options.Payload);
object target = destinationItem != null ? destinationItem.Item : null;
DropPosition position = destinationItem != null ? destinationItem.DropPosition : DropPosition.Inside;
if (source != null && target != null)
{
Section sourceSection = source as Section;
Section targetSection = target as Section;
Question sourceQuestion = source as Question;
Question targetQuestion = target as Question;
if (sourceQuestion != null)
{
try
{
if (sourceQuestion != null && targetQuestion != null && object.ReferenceEquals(sourceQuestion, targetQuestion))
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
if (targetQuestion != null && position == DropPosition.Inside)
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
if (position != DropPosition.Inside && targetQuestion == null)
{
sourceSection.Questions.Remove(sourceQuestion);
targetSection.Questions.Add(sourceQuestion);
e.QueryResult = false;
return;
}
}
catch (Exception ex)
{
}
}
}
else
{
e.QueryResult = false;
return;
}
e.QueryResult = true;
}
就是这个。您将能够拖放。
这里有很多信息:http ://www.telerik.com/help/silverlight/raddraganddrop-events.html
但我也遇到了树视图的问题。