Skip to content

Commit ff98cad

Browse files
"Hacky fix" to showcase what the root cause is
1 parent b496250 commit ff98cad

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,19 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
369369
var window = Window.GetWindow(dialogHost);
370370
dialogHost._restoreFocusDialogClose = window != null ? FocusManager.GetFocusedElement(window) : null;
371371

372+
/* The root cause of the issue is that dialogHost._restoreFocusDialogClose at this point is a TabItem.
373+
* So when trying to restore focus when the dialog closes, it will call .Focus() on the TabItem which
374+
* effectively does a tab switch if that TabItem is not currently the selected TabItem.
375+
*
376+
* This IS NOT the right fix, but showcases the issue. How can we go about creating a generic fix for this?
377+
* I don't believe TabControl is the only control which is facing this issue. Any control with state similar
378+
* to the TabControl would arguably suffer from the same issue.
379+
*/
380+
if (dialogHost._restoreFocusDialogClose is TabItem { Parent: TabControl tabControl })
381+
{
382+
dialogHost._restoreFocusDialogClose = tabControl;
383+
}
384+
372385
//multiple ways of calling back that the dialog has opened:
373386
// * routed event
374387
// * the attached property (which should be applied to the button which opened the dialog

0 commit comments

Comments
 (0)