0

我已将所有数据绑定到RadTreeView但无法使用拖放。我使用了四个属性作为

IsDragDropEnabled="True" 
IsDropPreviewLineEnabled="True"
AllowDrop="True"
IsDragPreviewEnabled="True"

我想在同一棵树中删除一个项目。但它不起作用。

4

3 回答 3

1

快速阅读这篇telerik 文章后,拖放似乎对我来说效果很好。

<telerik:RadTreeView ... EnableDragAndDrop="true" OnNodeDrop="MyTreeView_NodeDrop">

EnableDragAndDrop 和 OnNodeDrop 似乎是让它工作的两个重要部分,但不在您尝试的属性列表中。高温高压

于 2012-01-27T15:54:53.637 回答
1
 <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;

    }

就是这个。您将能够拖放。

于 2012-02-15T09:05:03.290 回答
1

这里有很多信息:http ://www.telerik.com/help/silverlight/raddraganddrop-events.html

但我也遇到了树视图的问题。

于 2011-07-01T11:40:44.087 回答