Explorar el Código

Wrap Clipboard.GetTextAsync in a try-catch to mimic WPF default behavior (#14505)

(in WPF this is configurable via FrameworkCompatibilityPreferences.ShouldThrowOnCopyOrCutFailure but by default in WPF it won't throw)
Bartosz Korczyński hace 1 año
padre
commit
b7d4efa147
Se han modificado 2 ficheros con 19 adiciones y 2 borrados
  1. 9 1
      src/Avalonia.Controls/MaskedTextBox.cs
  2. 10 1
      src/Avalonia.Controls/TextBox.cs

+ 9 - 1
src/Avalonia.Controls/MaskedTextBox.cs

@@ -216,7 +216,15 @@ namespace Avalonia.Controls
                 if (clipboard is null)
                     return;
 
-                var text = await clipboard.GetTextAsync();
+                string? text = null;
+                try
+                {
+                    text = await clipboard.GetTextAsync();
+                }
+                catch (TimeoutException)
+                {
+                    // Silently ignore.
+                }
 
                 if (text == null)
                     return;

+ 10 - 1
src/Avalonia.Controls/TextBox.cs

@@ -1147,7 +1147,16 @@ namespace Avalonia.Controls
             var clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
 
             if (clipboard != null)
-                text = await clipboard.GetTextAsync();
+            {
+                try
+                {
+                    text = await clipboard.GetTextAsync();
+                }
+                catch (TimeoutException)
+                {
+                    // Silently ignore.
+                }
+            }
 
             if (string.IsNullOrEmpty(text))
             {