File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
src/MaterialDesignThemes.Wpf Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments