New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update TreeView to support blocking drag&drop for specific items #1646
Conversation
dev/TreeView/TreeView.cpp
Outdated
m_dragItemsStartingEventSource(*this, *treeViewArgs); | ||
} | ||
|
||
void TreeView::OnListControlDragItemsCompleted(const winrt::IInspectable& sender, const winrt::DragItemsCompletedEventArgs& args) | ||
{ | ||
auto treeViewArgs = winrt::make_self<TreeViewDragItemsCompletedEventArgs>(); | ||
treeViewArgs->DragItemsCompletedEventArgs(args); | ||
winrt::IInspectable newParent = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should try to avoid scratch variables if possible, I might suggest the following:
const auto newParent = [items = args.Items(), listControl = ListControl(), rootNode = m_rootNode.get()]()
{
if (listControl && items && items.Size() > 0)
{
if (const auto draggedNode = listControl->NodeFromItem(items.GetAt(0)))
{
const auto parentNode = draggedNode.Parent();
if (parentNode && parentNode != rootNode)
{
return listControl->ItemFromNode(parentNode);
}
}
}
return static_cast<winrt::IInspectable>(nullptr);
}();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Might be a dumb question, but I want to enable the general reorder logic but need some specific checks: It sounds like this change made it possible to do so, but I don't understand how I would implement it with this change, can some one give me a example or some hints? |
@AignerGames I think that the answer is to set the CanDrag and AllowDrop properties on that parent node to false. |
Description
Enable TreeView to block drag&drop on certain items.
Added checks for "handled" in drag&drop callbacks so developers can set "handled" to true to skip TreeView built-in drag drop logic.
Also added a "NewParent" property in TreeViewDragItemsCompletedEventArgs, which makes it easier to figure out the drop position.
Motivation and Context
Fix #381
Fix #1154
How Has This Been Tested?
Updated existing test to include "NewParent" property.