-
Notifications
You must be signed in to change notification settings - Fork 711
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
Children property is not being updated after drag complete #1002
Comments
@kaiguo sounds similar to the other bug you fixed. It looks like this data source is observable so I think it's doing the right thing on the app side for this to work. |
Hey all, any updates on this issue? Let me know if I can help determine root cause. My customers have been asking for drag and drop in my app for 3 months now and this issue is blocking me. |
Looking at it now... |
@dpaulino Some operations are async due to the way ItemSource and Layout update works, so the children collection in ItemsSource doesn't have anything yet when you try to access it. It should work if you put your code in a dispatcher like this, private void TreeView_DragItemsCompleted(MUXC.TreeView sender, MUXC.TreeViewDragItemsCompletedEventArgs args)
{
if (args.Items[0] is ExplorerItem item)
{
var dispatcher = CoreApplication.MainView.Dispatcher;
var ignore = dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => {
ExplorerItem parent = GetParent(ViewModel.Nodes, item);
parent.Children.Remove(item);
ViewModel.Nodes.Add(item);
});
}
originalParent = null;
} I think you can probably consider overriding OnDrop method on TreeViewItem to prevent the operation happening from the beginning instead of manually "cancel" the drag&drop by swapping items back. |
I will try the OnDrop method, and I'll report back soon. |
@kaiguo can you point out exactly which "OnDrop" method I'm supposed to use? I tried the code below but the event is never fired when I drop a tree view item onto another tree view item.
Here's a branch you can clone to test out the above code: https://github.com/dpaulino/treeviewtest/tree/dropOnTreeViewItem |
By the way, it may be possible to close this issue if this question could be answered: #1154 |
Describe the bug
The
Children
property of an item is not being updated after a different item is dragged into it.Steps to reproduce the bug
second
into the item namedfirst
. This will trigger logic that effectively "cancels" the drop and reinsertssecond
back into the root list.first
intosecond
.Children
property ofsecond
was not updated.Expected behavior
No crash
Version Info
NuGet package version:
Microsoft.UI.Xaml 2.2.190702001-prerelease
Additional context
This may be related to my previous issue #631
The text was updated successfully, but these errors were encountered: