|
1 |
| -using System.ComponentModel; |
| 1 | +using System; |
| 2 | +using System.ComponentModel; |
| 3 | +using System.Windows.Controls; |
| 4 | +using System.Windows.Data; |
| 5 | +using Google.Protobuf.WellKnownTypes; |
2 | 6 | using MaterialDesignThemes.UITests.Samples.UpDownControls;
|
3 | 7 |
|
4 | 8 | namespace MaterialDesignThemes.UITests.WPF.UpDownControls;
|
@@ -215,4 +219,74 @@ public async Task NumericUpDown_WhenValueEqualsMinimum_DisableButtons(int value,
|
215 | 219 |
|
216 | 220 | recorder.Success();
|
217 | 221 | }
|
| 222 | + |
| 223 | + [Fact] |
| 224 | + [Description("Issue 3827")] |
| 225 | + public async Task NumericUpDown_WhenBindingUpdateTriggerIsPropertyChanged_ItUpdatesBeforeLoosingFocus() |
| 226 | + { |
| 227 | + await using var recorder = new TestRecorder(App); |
| 228 | + //Arrange |
| 229 | + var numericUpDown = await LoadXaml<NumericUpDown>(""" |
| 230 | + <materialDesign:NumericUpDown Tag="{Binding Value, RelativeSource={RelativeSource Self}, UpdateSourceTrigger=PropertyChanged}" Maximum="10" Minimum="1" /> |
| 231 | + """); |
| 232 | + |
| 233 | + var textBox = await numericUpDown.GetElement<TextBox>("PART_TextBox"); |
| 234 | + //Act |
| 235 | + await textBox.MoveKeyboardFocus(); |
| 236 | + await textBox.SendKeyboardInput($"{ModifierKeys.Control}{Key.A}{ModifierKeys.None}4"); |
| 237 | + |
| 238 | + //Act |
| 239 | + object? tag = await numericUpDown.GetTag(); |
| 240 | + |
| 241 | + //Assert |
| 242 | + Assert.Equal("4", tag?.ToString()); |
| 243 | + |
| 244 | + recorder.Success(); |
| 245 | + } |
| 246 | + |
| 247 | + [Fact] |
| 248 | + [Description("Issue 3827")] |
| 249 | + public async Task NumericUpDown_WhenBindingUpdateTriggerIsLostFocus_ItDoesNotUpdateUntilItLoosesFocus() |
| 250 | + { |
| 251 | + await using var recorder = new TestRecorder(App); |
| 252 | + //Arrange |
| 253 | + var userControl = await LoadUserControl<BoundNumericUpDown>(); |
| 254 | + var numericUpDown = await userControl.GetElement<NumericUpDown>(); |
| 255 | + var buttonToFocus = await userControl.GetElement<Button>("btnToFocus"); |
| 256 | + await numericUpDown.SetValue(2); |
| 257 | + |
| 258 | + static void SetBindingToLostFocus(NumericUpDown numericUpDown) |
| 259 | + { |
| 260 | + var binding = new Binding(nameof(NumericUpDown.Value)) |
| 261 | + { |
| 262 | + Path = new(nameof(BoundNumericUpDownViewModel.Value)), |
| 263 | + UpdateSourceTrigger = UpdateSourceTrigger.LostFocus |
| 264 | + }; |
| 265 | + BindingOperations.SetBinding(numericUpDown, NumericUpDown.ValueProperty, binding); |
| 266 | + } |
| 267 | + await numericUpDown.RemoteExecute(SetBindingToLostFocus); |
| 268 | + |
| 269 | + var textBox = await numericUpDown.GetElement<TextBox>("PART_TextBox"); |
| 270 | + |
| 271 | + static int GetViewModelValue(NumericUpDown numericUpDown) |
| 272 | + { |
| 273 | + return ((BoundNumericUpDownViewModel)numericUpDown.DataContext).Value; |
| 274 | + } |
| 275 | + |
| 276 | + //Act |
| 277 | + await textBox.MoveKeyboardFocus(); |
| 278 | + await textBox.SendKeyboardInput($"{ModifierKeys.Control}{Key.A}{ModifierKeys.None}4"); |
| 279 | + |
| 280 | + //Act |
| 281 | + int valueBeforeLostFocus = await numericUpDown.RemoteExecute(GetViewModelValue); |
| 282 | + await textBox.SendKeyboardInput($"{Key.Tab}"); |
| 283 | + int valueAfterLostFocus = await numericUpDown.RemoteExecute(GetViewModelValue); |
| 284 | + |
| 285 | + |
| 286 | + //Assert |
| 287 | + Assert.Equal("2", valueBeforeLostFocus.ToString()); |
| 288 | + Assert.Equal("4", valueAfterLostFocus.ToString()); |
| 289 | + |
| 290 | + recorder.Success(); |
| 291 | + } |
218 | 292 | }
|
0 commit comments