Open ivansp opened 6 years ago
Seems like you posted a workaround on SO: https://stackoverflow.com/questions/47968536/uwp-winrt-xaml-toolkit-treeview-in-flyout-changes-selection-after-flyout-clos/47976018#47976018
As I said previously it seems this is a bug in WinRT TreeView component however I managed to prevent (hard fix) this behavior by binding "IsEnabled" property to IsFiltersOpen property from my ViewModel. This way when I select my element I close the Flyout and disable TreeView component, which prevents it from updating.
Yep sorry for late reply, wasn't sure if anyone was still checking issues on here. But yes, I inspected TreeView component locally and realized it was checking for IsEnabled property when updating selection so I binded that property to view models's IsFlyoutOpen.
Seems to solve the issue for my use case. Still it's kind of a "hard-fix" if you will.
A workaround is better than nothing and sometimes it's even better than a fix if the fix introduces new bugs... ;)
I am currently trying to use WinRT xaml ToolKit TreeView component since it is not supported in UWP natively.
TreeView is inside a button Flyout. When I press the button I want Flyout to appear so I can select an item from the tree. And I bind a command from ViewModel to SelectedItemChanged event:
After I select an item from TreeView, SelectedItemChanged event fires as it should, but afterwards I close the Flyout and the event fires again. The second time it usually fires saying new selected element is next after current's parent. So for example if I have this structure:
So if I select --1.1 first SelectedItemChanged will fire with --1.1 element, and afterwards it will fire with 2 as new selected item.
Note: I am using CustomFlyout component which I can close from ViewModel, but I also tested this with regular Flyout and same thing happens after I close Flyout by clicking outside of it.
UPDATE: I've downloaded WinRT code and started debugging the TreeView component locally. In TreeViewItem.cs I've found the source of the problem in this function:
From what I can tell when element gets focus sometimes it fails to find it's parent and prevent propagating the event upwards in the tree.
Can anyone help me out with this issue?