MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit
Refocus after Dialog close triggers Tab change
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 16.3k
- Forks
- 3.5k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 8
Description
The DialogHost tries to "re-focus" the item previously selected. This is the code for it:
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/5533b50a6cff78cb75fbb52e16f7c9e06c62446c/MaterialDesignThemes.Wpf/DialogHost.cs#L268
This is very problematic, when the previous control was a `TabItem`, because Focus()ing a `TabItem` actually activates the respective tab.
Here is a very simple reproduction:
* Have a TabControl within a DialogHost
* Focus a given TabItem (i.e. by clicking on an already active Tab)
* In the SelectionChanging Event of the TabControl Show the Dialog (i.e. "Loading data ...")
* Click another Tab
The following happens:
* DialogHost remembers, that the first tab is currently focused
* The click on the second Tab activates this Tab
* Dialog is shown and closed again, after data is loaded
* Dialog calls Focus() on first tab
=> First tab will be selected again
I just created the issue as I'm not sure, what the best solution for this. My current feeling tells me to just check for `if(!(dialogHost._restoreFocusDialogClose is TabItem)`, but there might be other elements, where a re-focus is not desired?
I'd be happy to provide a PR after we agree on a solution.
Also - for now, I'd welcome any idea for a good workaround I could place into the application to make it work for now.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DialogHost.cs around line 268 and reproduce the interaction with a TabControl, TabItem, and SelectionChanging handler that opens a dialog. Investigate whether restoring focus to the previously selected element should be skipped or handled differently for tab items, and verify that closing the dialog leaves the newly selected tab active.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100