|
|
|
@ -401,6 +401,53 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TextBox_GotFocus_And_LostFocus_Work_Properly() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(FocusServices)) |
|
|
|
{ |
|
|
|
var target1 = new TextBox |
|
|
|
{ |
|
|
|
Template = CreateTemplate(), |
|
|
|
Text = "1234" |
|
|
|
}; |
|
|
|
var target2 = new TextBox |
|
|
|
{ |
|
|
|
Template = CreateTemplate(), |
|
|
|
Text = "5678" |
|
|
|
}; |
|
|
|
var sp = new StackPanel(); |
|
|
|
sp.Children.Add(target1); |
|
|
|
sp.Children.Add(target2); |
|
|
|
|
|
|
|
var root = new TestRoot { Child = sp }; |
|
|
|
|
|
|
|
var gfcount = 0; |
|
|
|
var lfcount = 0; |
|
|
|
|
|
|
|
target1.GotFocus += (s, e) => gfcount++; |
|
|
|
target2.LostFocus += (s, e) => lfcount++; |
|
|
|
|
|
|
|
target2.Focus(); |
|
|
|
Assert.False(target1.IsFocused); |
|
|
|
Assert.True(target2.IsFocused); |
|
|
|
|
|
|
|
target1.Focus(); |
|
|
|
Assert.False(target2.IsFocused); |
|
|
|
Assert.True(target1.IsFocused); |
|
|
|
|
|
|
|
Assert.Equal(1, gfcount); |
|
|
|
Assert.Equal(1, lfcount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static TestServices FocusServices => TestServices.MockThreadingInterface.With( |
|
|
|
focusManager: new FocusManager(), |
|
|
|
keyboardDevice: () => new KeyboardDevice(), |
|
|
|
keyboardNavigation: new KeyboardNavigationHandler(), |
|
|
|
inputManager: new InputManager(), |
|
|
|
standardCursorFactory: Mock.Of<IStandardCursorFactory>()); |
|
|
|
|
|
|
|
private static TestServices Services => TestServices.MockThreadingInterface.With( |
|
|
|
standardCursorFactory: Mock.Of<IStandardCursorFactory>()); |
|
|
|
|
|
|
|
|