Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Only calling set focus one when dialog is opened.
  • Loading branch information
Keboo committed Feb 13, 2024
commit e92572af9349b712a6e76a21884811475ee815f4
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace MaterialDesignThemes.UITests.WPF.DialogHosts;

public class DialogHostTests : TestBase
public class DialogHostTests(ITestOutputHelper output) : TestBase(output)
{
public DialogHostTests(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task OnOpenDialog_OverlayCoversContent()
{
Expand Down
28 changes: 14 additions & 14 deletions MaterialDesignThemes.Wpf/DialogHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ 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 @@ -433,8 +432,8 @@ public PlacementMode Placement

public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
get => (CornerRadius)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}

public static readonly DependencyProperty DialogContentProperty = DependencyProperty.Register(
Expand Down Expand Up @@ -652,8 +651,8 @@ public bool IsRestoreFocusDisabled
/// </summary>
public event DialogOpenedEventHandler DialogOpened
{
add { AddHandler(DialogOpenedEvent, value); }
remove { RemoveHandler(DialogOpenedEvent, value); }
add => AddHandler(DialogOpenedEvent, value);
remove => RemoveHandler(DialogOpenedEvent, value);
}

/// <summary>
Expand Down Expand Up @@ -699,8 +698,8 @@ protected void OnDialogOpened(DialogOpenedEventArgs eventArgs)
/// </summary>
public event DialogClosingEventHandler DialogClosing
{
add { AddHandler(DialogClosingEvent, value); }
remove { RemoveHandler(DialogClosingEvent, value); }
add => AddHandler(DialogClosingEvent, value);
remove => RemoveHandler(DialogClosingEvent, value);
}

/// <summary>
Expand Down Expand Up @@ -742,8 +741,8 @@ protected void OnDialogClosing(DialogClosingEventArgs eventArgs)
/// </summary>
public event DialogClosedEventHandler DialogClosed
{
add { AddHandler(DialogClosedEvent, value); }
remove { RemoveHandler(DialogClosedEvent, value); }
add => AddHandler(DialogClosedEvent, value);
remove => RemoveHandler(DialogClosedEvent, value);
}

/// <summary>
Expand Down Expand Up @@ -819,6 +818,11 @@ internal void InternalClose(object? parameter)
var child = _popup?.Child ?? _popupContentControl;
if (child is null) return null;

if (PresentationSource.FromVisual(child) is HwndSource hwndSource)
{
SetFocus(hwndSource.Handle);
}

CommandManager.InvalidateRequerySuggested();
var focusable = child.VisualDepthFirstTraversal().OfType<UIElement>().FirstOrDefault(ui => ui.Focusable);
if (focusable is null) return null;
Expand Down Expand Up @@ -954,11 +958,7 @@ 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]
Expand Down