【问题标题】:Unable to use drag Drop in radtreeview无法在 radtreeview 中使用拖放
【发布时间】:2011-03-21 14:19:22
【问题描述】:

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

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

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

【问题讨论】:

  • 您能否提供更多相关信息,什么不起作用?

标签: radtreeview


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    在快速阅读this telerik article 之后,拖放似乎对我来说效果很好。

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

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

    【讨论】:

      【解决方案3】:
       <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;
      
          }
      

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

      【讨论】:

        猜你喜欢
        • 2011-03-07
        • 1970-01-01
        • 2014-09-06
        • 1970-01-01
        • 2021-07-29
        • 1970-01-01
        • 2022-06-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多