Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions MaterialDesignThemes.Wpf/DialogHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Runtime.InteropServices;
using System.Security;
using System.Windows.Data;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;

Expand Down Expand Up @@ -284,6 +287,7 @@ public DialogHost()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
PreviewGotKeyboardFocus += OnPreviewGotKeyboardFocus;

CommandBindings.Add(new CommandBinding(CloseDialogCommand, CloseDialogHandler, CloseDialogCanExecute));
CommandBindings.Add(new CommandBinding(OpenDialogCommand, OpenDialogHandler));
Expand Down Expand Up @@ -947,4 +951,17 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
}
}
}

private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
if (_popup != null &&
PresentationSource.FromVisual(_popup.Child) is HwndSource hwndSource)
{
SetFocus(hwndSource.Handle);
}
}

[SecurityCritical]
[DllImport("user32.dll", EntryPoint = "SetFocus", SetLastError = true)]
private static extern IntPtr SetFocus(IntPtr hWnd);
}