NavigationView : selecting a Child viewItem programmatically doesn't work (same issue when removing selected child item programmatically)
Describe the bug
NavigationView : selecting a Child viewItem programmatically doesn't work
I have a navigationView with menuItems. Some menuItems have child MenuItems. Selected by code a child menu items provokes several bugs.
The first one is that selection indicator is not displayed, even if item has selected background color (see picture).
I have other problems but they are hard to explain, and I think the main cause is the same one.
I think the problems comes from the fact that it is unexpected by the library that we select a child item without expanding parent.
To bypass my problems, I had to :
- set IsExpanded on parent viewItem
- wait for childItem to be loaded
- set navigationView.SelectedItem = childItem
I have managed to bypass the different issues with similar tricks. I create this issue for your information but I don't need a fix personally.
Regards
Reproduction
See description
Suggested Solution
No response
Library Version
0.10.0
Operating System
Windows 11
Framework
.NET Framework
Framework Version
4.5.2
Source of Package
Self-Compiled
Additional Notes
No response
Validations
- [x] Check that there isn't already an issue that reports the same or similar problem.
- [x] Check that this is a bug in the library that should be fixed, not a feature, also this is not about the documentation. (Or please choose the right repo and template.)
- [x] This is one single problem, or a few problems with the same cause. (If you want to report multiple problems, please create one issue for every single problem.)
- [x] You've checked that this problem still exists in the latest version. (Keep in mind that we don't provide any support for old versions.)
- [x] You know that we can't guarantee that we will satisfy your request. This is not really our duty to do everything anyone asks for. Also, you will treat our staff, contributors, and other users with respect and kindness.
- [x] You're sure there's something wrong with the library itself, not how you're using it. (If you are having issues using it and need help, please go to discussion.)
Could you please provide a minimum reproducible repository if possible? That would help us a lot investigating this issue.
Here it is !
NavigationView_SetChildItemAsSelectedItem.zip
Edit : In the sample, you also have some code to bypass the problem. However, I don't like it because selection is not directly modified on click (had to wait until Loaded event).
Edit IMPORTANT : In the sample, the some used to bypass the problem seems to break the selection model, because if I them remove all child items (one at a time) programmatically after this, I get some crash when removing the last child item.
I'm sorry but I really need your help on this issue. I cannot find a way to bypass the problem : whatevet I try, it seems that I get a corrupted SelectionModel and I have many different problems after a while (selection refused, crash...).
Any hint to bypass the problem would be really appreciated.
I'm really busy these days, so I'm afraid I have no time to look into all issues here right now. @JPDelprat I'll check them later when I'm available (in about a month), or you can ask other contributors to have a look.
Thank you very much.
I understand perfectly that you're busy. I was just hoping for a little hint, without any investigation on your part, based on your knowledge.
I'm sorry, I didn't mean to be so insistent. I was just a bit desperate at one point.
Anyway, for the time being, I've found a trick to avoid crashes. I'm sure SelectionModel is still corrupt, but I can wait a while without any problems.
Some information for when you're available.
What I do is :
- create child elements dynamically
- force selection by code
- delete child elements dynamically
In addition, I'm changing the visibility of group elements so that they are collapsed when there are no children, but this doesn't seem to change anything.
I'm sure NavigationView works fine if I define all my elements at startup and just select them with my mouse, but I'm not sure dynamic changes are taken into account properly (at least for child elements because they're not loaded / top-level elements seem fine).
Thanks again.
Another related problem (after creating child items programmatically as indicated above) ; I don't know if the problems occurs if items are created from the beginning.
I have a navigation view with a group containing two items. I select the second item.
Now, on a button click for example, I remove second item programmatically => first item becomes selected On another button click, I remove first item programmatically => crash in NavigationView SelectionModel