我正在使用这个示例代码:
private TreeViewItem GetNearestContainer(UIElement element)
{
// Walk up the element tree to the nearest tree view item.
TreeViewItem container = element as TreeViewItem;
while ((container == null) && (element != null))
{
element = VisualTreeHelper.GetParent(element) as UIElement;
container = element as TreeViewItem;
}
return container;
}
在运行时,UIElement
显示为 a TextBlock
(实际上是TreeViewItem
被拖动),并且在这一行:
TreeViewItem container = element as TreeViewItem
即使元素是一个TextBlock
. 这是否意味着它不能正确投射?我正在尝试Drag and Drop
使用这篇文章来实现。