Skip to content

Commit 9e966e4

Browse files
authored
Invalidates visual after dialog opens (#3882)
Wait for the animations to have some time to run before moving focus to the dialog. this prevents focus jumps on fast double clicks Fixes #2912
1 parent d5c7d2f commit 9e966e4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,16 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
393393
dialogHost.DialogOpenedCallback?.Invoke(dialogHost, dialogOpenedEventArgs);
394394
dialogHost._asyncShowOpenedEventHandler?.Invoke(dialogHost, dialogOpenedEventArgs);
395395

396-
dialogHost.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
397-
{
396+
//https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/187
397+
//totally not happy about this, but on immediate validation we can get some weird looking stuff...give WPF a kick to refresh...
398+
Task.Delay(300).ContinueWith(t => dialogHost.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
398399
CommandManager.InvalidateRequerySuggested();
400+
//Delay focusing the popup until after the animation has some time, Issue #2912
399401
UIElement? child = dialogHost.FocusPopup();
400402

401-
if (child != null)
402-
{
403-
//https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/187
404-
//totally not happy about this, but on immediate validation we can get some weird looking stuff...give WPF a kick to refresh...
405-
Task.Delay(300).ContinueWith(t => child.Dispatcher.BeginInvoke(new Action(() => child.InvalidateVisual())));
406-
}
407-
}));
403+
child?.InvalidateVisual();
404+
405+
})));
408406
}
409407

410408
/// <summary>

0 commit comments

Comments
 (0)