Browse Source
Merge pull request #6151 from workgroupengineering/fixes/Issue_6100
Fixes issue 6100
pull/6187/head
Max Katz
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
61 additions and
2 deletions
-
src/Avalonia.Controls/ComboBox.cs
-
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
|
|
|
@ -205,7 +205,7 @@ namespace Avalonia.Controls |
|
|
|
if (e.Handled) |
|
|
|
return; |
|
|
|
|
|
|
|
if (e.Key == Key.F4 || |
|
|
|
if ((e.Key == Key.F4 && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == false) || |
|
|
|
((e.Key == Key.Down || e.Key == Key.Up) && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt))) |
|
|
|
{ |
|
|
|
IsDropDownOpen = !IsDropDownOpen; |
|
|
|
|
|
|
|
@ -201,6 +201,65 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Close_Window_On_Alt_F4_When_ComboBox_Is_Focus() |
|
|
|
{ |
|
|
|
var inputManagerMock = new Moq.Mock<IInputManager>(); |
|
|
|
var services = TestServices.StyledWindow.With(inputManager: inputManagerMock.Object); |
|
|
|
|
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var window = new Window(); |
|
|
|
|
|
|
|
window.KeyDown += (s, e) => |
|
|
|
{ |
|
|
|
if (e.Handled == false |
|
|
|
&& e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == true |
|
|
|
&& e.Key == Key.F4 ) |
|
|
|
{ |
|
|
|
e.Handled = true; |
|
|
|
window.Close(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
var count = 0; |
|
|
|
|
|
|
|
var target = new ComboBox |
|
|
|
{ |
|
|
|
Items = new[] { new Canvas() }, |
|
|
|
SelectedIndex = 0, |
|
|
|
Template = GetTemplate(), |
|
|
|
}; |
|
|
|
|
|
|
|
window.Content = target; |
|
|
|
|
|
|
|
|
|
|
|
window.Closing += |
|
|
|
(sender, e) => |
|
|
|
{ |
|
|
|
count++; |
|
|
|
}; |
|
|
|
|
|
|
|
window.Show(); |
|
|
|
|
|
|
|
target.Focus(); |
|
|
|
|
|
|
|
_helper.Down(target); |
|
|
|
_helper.Up(target); |
|
|
|
Assert.True(target.IsDropDownOpen); |
|
|
|
|
|
|
|
target.RaiseEvent(new KeyEventArgs |
|
|
|
{ |
|
|
|
RoutedEvent = InputElement.KeyDownEvent, |
|
|
|
KeyModifiers = KeyModifiers.Alt, |
|
|
|
Key = Key.F4 |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, count); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|