Skip to content

Commit 489dadc

Browse files
committed
Update ContentWindow.cs
1 parent f674751 commit 489dadc

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

dev/DevWinUI/Controls/Ported/Dialogs/ContentWindow/ContentWindow.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using System.ComponentModel;
44
using Microsoft.UI.Windowing;
5+
using Microsoft.UI.Xaml.Input;
56

67
namespace DevWinUI;
78

@@ -796,16 +797,19 @@ private void OnAppWindowStateChanged(AppWindow sender, AppWindowChangedEventArgs
796797
}
797798
}
798799

800+
private UIElement? _lastFocusedElement;
799801
private void OnWindowActivated(object sender, WindowActivatedEventArgs args)
800802
{
801803
switch (args.WindowActivationState)
802804
{
803805
case WindowActivationState.Deactivated:
806+
_lastFocusedElement = FocusManager.GetFocusedElement(XamlRoot) as UIElement;
804807
Deactivated?.Invoke(this, EventArgs.Empty);
805808
break;
806809

807810
case WindowActivationState.CodeActivated:
808811
case WindowActivationState.PointerActivated:
812+
(_lastFocusedElement ?? this).Focus(FocusState.Programmatic);
809813
Activated?.Invoke(this, EventArgs.Empty);
810814
break;
811815

0 commit comments

Comments
 (0)