@@ -298,55 +298,53 @@ public string Text
298
298
var oldText = Text ;
299
299
CurrentText = null ;
300
300
var newText = value ?? string . Empty ;
301
- TextBox . BeginChange ( ) ;
302
- if ( newText != oldText )
303
- {
304
- var args = new TextChangingEventArgs ( oldText , newText , false ) ;
305
- Callback . OnTextChanging ( Widget , args ) ;
306
- if ( args . Cancel )
307
- {
308
- TextBox . EndChange ( ) ;
309
- return ;
310
- }
301
+ if ( newText == oldText )
302
+ return ;
311
303
312
- var needsTextChanged = TextBox . Text == newText ;
304
+ var args = new TextChangingEventArgs ( oldText , newText , false ) ;
305
+ Callback . OnTextChanging ( Widget , args ) ;
306
+ if ( args . Cancel )
307
+ return ;
313
308
314
- // Improve performance when setting text often
315
- // See https://github.com/dotnet/wpf/issues/5887#issuecomment-1604577981
316
- var endNoGCRegion = EnableNoGCRegion
317
- && GCSettings . LatencyMode != GCLatencyMode . NoGCRegion ;
309
+ var needsTextChanged = TextBox . Text == newText ;
318
310
319
- try
320
- {
321
- endNoGCRegion &= GC . TryStartNoGCRegion ( 1000000 ) ; // is this magic number reasonable??
322
- }
323
- catch
324
- {
325
- // Ignore any exceptions, they can apparently still happen even though we check the LatencyMode above
326
- endNoGCRegion = false ;
327
- }
311
+ // Improve performance when setting text often
312
+ // See https://github.com/dotnet/wpf/issues/5887#issuecomment-1604577981
313
+ var endNoGCRegion = EnableNoGCRegion
314
+ && GCSettings . LatencyMode != GCLatencyMode . NoGCRegion ;
328
315
329
- try
330
- {
331
- TextBox . Text = newText ;
332
- }
333
- finally
334
- {
335
- if ( endNoGCRegion && GCSettings . LatencyMode == GCLatencyMode . NoGCRegion )
336
- GC . EndNoGCRegion ( ) ;
337
- }
338
-
339
- if ( needsTextChanged )
340
- {
341
- Callback . OnTextChanged ( Widget , EventArgs . Empty ) ;
342
- }
316
+ try
317
+ {
318
+ endNoGCRegion &= GC . TryStartNoGCRegion ( 1000000 ) ; // is this magic number reasonable??
343
319
}
320
+ catch
321
+ {
322
+ // Ignore any exceptions, they can apparently still happen even though we check the LatencyMode above
323
+ endNoGCRegion = false ;
324
+ }
325
+
326
+ try
327
+ {
328
+ TextBox . Text = newText ;
329
+ }
330
+ finally
331
+ {
332
+ if ( endNoGCRegion && GCSettings . LatencyMode == GCLatencyMode . NoGCRegion )
333
+ GC . EndNoGCRegion ( ) ;
334
+ }
335
+
344
336
if ( value != null && AutoSelectMode == AutoSelectMode . Never && ! HasFocus )
345
337
{
338
+ TextBox . BeginChange ( ) ;
346
339
TextBox . SelectionStart = value . Length ;
347
340
TextBox . SelectionLength = 0 ;
341
+ TextBox . EndChange ( ) ;
342
+ }
343
+
344
+ if ( needsTextChanged )
345
+ {
346
+ Callback . OnTextChanged ( Widget , EventArgs . Empty ) ;
348
347
}
349
- TextBox . EndChange ( ) ;
350
348
}
351
349
}
352
350
0 commit comments