Skip to content

Commit a0c440c

Browse files
corvinszKeboo
andauthored
Apply suggestions from code review
LGTM, thank you for the review! Co-authored-by: Kevin B <[email protected]>
1 parent 31fec8b commit a0c440c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
412412

413413
private void ListenForWindowStateChanged(Window? window)
414414
{
415-
window ??= Window.GetWindow(this);
416415

417416
if (window is not null)
418417
{
418+
window.StateChanged -= Window_StateChanged;
419419
window.StateChanged += Window_StateChanged;
420420
}
421421
}
@@ -437,12 +437,15 @@ private void Window_StateChanged(object? sender, EventArgs e)
437437

438438
// We only need to focus anything manually if the window changes state from Minimized --> (Normal or Maximized)
439439
// Going from Normal --> Maximized (and vice versa) is fine since the focus is already kept correctly
440-
if (IsWindowRestoredFromMinimized() && IsLastFocusedDialogElementFocusable())
440+
if (IsWindowRestoredFromMinimized())
441441
{
442442
// Kinda hacky, but without a delay the focus doesn't always get set correctly because the Focus() method fires too early
443443
Task.Delay(50).ContinueWith(_ => this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
444444
{
445-
_lastFocusedDialogElement!.Focus();
445+
if (IsLastFocusedDialogElementFocusable())
446+
{
447+
_lastFocusedDialogElement!.Focus();
448+
}
446449
})));
447450
}
448451
_previousWindowState = windowState;

0 commit comments

Comments
 (0)