执行拖放操作时,不要在其子节点上删除父节点

时间:2017-04-11 10:52:05

标签: c# xml linq-to-xml objectlistview

<?xml version="1.0" encoding="utf-8"?>
<Book name="Book" UID="0" State="Checked">
  <Book1 name="Book1" UID="1" DataSourceId="1" State="Checked">
    <NoteBook name="NoteBook1" State="Checked" UID="3">
    </NoteBook>
    <NoteBook name="NoteBook2" State="Checked" UID="4">
    </NoteBook>              
  </Book1>
</Book>

我正在进行拖放操作,以便我选择节点Book1(拖动节点)并放在NoteBook2(丢弃节点)上,因为父节点不是其子节点的子节点,因此无效用户操作。我需要验证目标节点是否不是祖先

 var sourceModels = e.SourceModels.Cast<XElement>();
                    XElement targetModels = e.TargetModel as XElement;

                    if (sourceModels.Any(x => targetModels.Ancestors("")//something like this
                        e.InfoMessage = "Cannot drop on descendant (think of the temporal paradoxes!)";
                    else
                        e.Effect = DragDropEffects.Move; 

0 个答案:

没有答案