Skip to content

Commit fff21fa

Browse files
authored
Fix lost mouse clicks on inactive window (#1021) (#1710)
* Fix lost mouse clicks on inactive window (#1021) * Removed DialogHost.OnPreviewMouseDown (#1021) * Restored DialogHost.OnPreviewMouseDown, removed logic to restore focus on activation (#1021)
1 parent e1f8971 commit fff21fa

File tree

1 file changed

+1
-39
lines changed

1 file changed

+1
-39
lines changed

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public class DialogHost : ContentControl
6868
private DialogOpenedEventHandler _attachedDialogOpenedEventHandler;
6969
private DialogClosingEventHandler _attachedDialogClosingEventHandler;
7070
private IInputElement _restoreFocusDialogClose;
71-
private IInputElement _restoreFocusWindowReactivation;
7271
private Action _currentSnackbarMessageQueueUnPauseAction;
73-
private Action _closeCleanUp = () => { };
7472

7573
static DialogHost()
7674
{
@@ -241,7 +239,6 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
241239

242240
if (dialogHost.IsOpen)
243241
{
244-
WatchWindowActivation(dialogHost);
245242
dialogHost._currentSnackbarMessageQueueUnPauseAction = dialogHost.SnackbarMessageQueue?.Pause();
246243
}
247244
else
@@ -254,7 +251,6 @@ private static void IsOpenPropertyChangedCallback(DependencyObject dependencyObj
254251
}
255252
dialogHost.CurrentSession.IsEnded = true;
256253
dialogHost.CurrentSession = null;
257-
dialogHost._closeCleanUp();
258254
//NB: _dialogTaskCompletionSource is only set in the case where the dialog is shown with Show
259255
//To get into this case you need to display the dialog with Show and then hide it by setting IsOpen to false
260256
//Setting this here ensures the other
@@ -627,7 +623,7 @@ internal UIElement FocusPopup()
627623

628624
return child;
629625
}
630-
626+
631627
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
632628
{
633629
var window = Window.GetWindow(this);
@@ -712,39 +708,5 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
712708
LoadedInstances.Add(this);
713709
}
714710

715-
private static void WatchWindowActivation(DialogHost dialogHost)
716-
{
717-
var window = Window.GetWindow(dialogHost);
718-
if (window != null)
719-
{
720-
window.Activated += dialogHost.WindowOnActivated;
721-
window.Deactivated += dialogHost.WindowOnDeactivated;
722-
dialogHost._closeCleanUp = () =>
723-
{
724-
window.Activated -= dialogHost.WindowOnActivated;
725-
window.Deactivated -= dialogHost.WindowOnDeactivated;
726-
};
727-
}
728-
else
729-
{
730-
dialogHost._closeCleanUp = () => { };
731-
}
732-
}
733-
734-
private void WindowOnDeactivated(object sender, EventArgs eventArgs)
735-
{
736-
_restoreFocusWindowReactivation = _popup != null ? FocusManager.GetFocusedElement((Window)sender) : null;
737-
}
738-
739-
private void WindowOnActivated(object sender, EventArgs eventArgs)
740-
{
741-
if (_restoreFocusWindowReactivation != null)
742-
{
743-
Dispatcher.BeginInvoke(new Action(() =>
744-
{
745-
Keyboard.Focus(_restoreFocusWindowReactivation);
746-
}));
747-
}
748-
}
749711
}
750712
}

0 commit comments

Comments
 (0)