Windowstemplatestudio: TreeViewPage Exception on Drop TreeViewItem

Created on 7 Feb 2021  路  6Comments  路  Source: microsoft/WindowsTemplateStudio

In a UWP generated app with a TreeView page, you can drag and drop TreeViewItems to reorder or move into another entity, but there is no prevention of dropping an item at an incorrect level. When the user does this there is an unhandled exception.

Steps to reproduce the behavior:

  1. Generate UWP application that includes a TreeView page.
  2. Launch application.
  3. Go to TreeView page.
  4. Drag a Company.
  5. Drop Company over an Order.
  6. Exception.

Expected behavior
I'd expect the incorrect drop action to be automatically dismissed/ignored, but at a minimum a gracefully handled exception.

C# Generated Code UWP VB bug

All 6 comments

Nice catch. I didn't even know the TreeView had built-in support for dragging to reorder.

Investigating how to avoid the exception. For the sample data that is included in the generated code, failing silently seems like the most appropriate action.

Aside: according to the documentation, the ability to drag and reorder items is disabled by default but this doesn't appear to be the case. I will also investigate this further.

It seems there's no easy workaround for this.
The underlying WinUI code simply adds the dragged item to the new parent collection without any form of validation or opportunity for capturing the exception that this scenario creates.

I propose the following:

  1. Change the generated code to disable dragging and reordering of items in the TreeView page. (This will match the behavior that existed prior to RS5/1809.)
  2. Raise a request on the WinUI repository to add an option for handling this scenario. I'm thinking a DragItemsCompleting event that allows for client code to validate the item being dropped and the location/container/collection it will be added to. This event would also allow for the drop/reordering to be cancelled by the client code

Note. This is possibly also connected with https://github.com/microsoft/microsoft-ui-xaml/issues/2328

Added a PR to disable the possibility to reorder items in the generated code.

Added a PR to disable the possibility to reorder items in the generated code.

Why just this property and not disabling item dragging as well?
Have you verified the issue separately?
Will you raise the WinUI issue (with minimal repro) too?

I've check that set CanDragItems to false does not fix the Issue, however I'll open an Issue in WinUI repo to better understand what is it design for.

I've created a minimum repro app that throws this exception on items dragging.
TreeViewDragAndDropIssue.zip

I've opened an issue with your suggestion in WinUI repo.
https://github.com/microsoft/microsoft-ui-xaml/issues/4135

Was this page helpful?
0 / 5 - 0 ratings