Przeglądaj źródła

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 1 rok temu
rodzic
commit
b7d4efa147

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

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

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

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