Avalonia
Avalonia copied to clipboard
Combobox in Datagrid's index reset to -1 after changing tab
Describe the bug It is possible to run into a situation where a Combobox in a datagrid can have its index reset to -1 when changing tab. I am linking here a very small project which allows to reproduce this issue.
To Reproduce Steps to reproduce the behavior:
- Open and compile the provided project
- Go to the "Party" tab
- Observe the items in the combobox being rendered correctly (see the code for details, it just adds 3 integers with the descriptions being hardcoded)
- Go to the "Global" tab
- Go BACK to the "Party" tab
- Observe the comboox showing nothing. The selected index actually was set to -1 when step 4 occured.
Expected behavior To have the combobox retain their values after switching tabs
Screenshots
Before switching tabs:
After switching tab:
Desktop (please complete the following information):
- OS: Windows 10
- Version 0.10.0
Additional context Here is the zip that can reproduce this issue: ComboboxIssueSample.zip
I wanted to try to debug this issue myself, but I am not sure the problem is related to the datagrid after all: it's as if changing tabs causes a binding update to the old tab which isn't valid because the bindings no longer works as the selected tab has changed. It gives me the impression that there's somehow a lingering binding that shouldn't be updated as you go to another tab.
More debugging: nvm it is related to the datagrid. So what seems to happen is when I change to the other tabs, it sets the old one's dataControl to null which cascades into the childs. If it's just a simple comboBox, it won't cause a set to the dataContext because the updateState isn't null (since it was set before thanks to the dataContext notifier thing). But if it's a combobox INSIDE a datagrid, the notifier won't propagate to the combobox which means that its updateState is null by the time there is a ClearRows ran on the dataGrid due to the Items property getting set to null. So by the time the items of the comboBox is set to null, it will call the setter of the selectedIndex on the DataContext.
Wouldn't fixing this involve something like implementing OnDataContextBeginUpdate
and OnDataContextEndUpdate
on the DataGrid to have this propagate to the cells?
I've downloaded your example and can confirm the issue. A solution I don't have for now. Only workaround I can offer atm is to use EditingTemplate. This means, your CBox will only appear if you double-click into the cell. [F2] also works.
Happy coding Tim
I've downloaded your example and can confirm the issue. A solution I don't have for now. Only workaround I can offer atm is to use EditingTemplate. This means, your CBox will only appear if you double-click into the cell. [F2] also works.
Happy coding Tim
I appreciate the info, but unfortunately, it wouldn't match with my current usecase because of needing to do something to make it appear. I actually DID had a workaround to this requiring to ignore any set to index -1 (since I happened to not need it in this case). I since really disliked this hack so I am trying to see if I can gather enough informations about how avalonia works to see if I can help get a fix going.