Browse Source

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)
pull/14530/head
Bartosz Korczyński 3 years ago
committed by GitHub
parent
commit
b7d4efa147
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      src/Avalonia.Controls/MaskedTextBox.cs
  2. 11
      src/Avalonia.Controls/TextBox.cs

10
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;

11
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))
{ {

Loading…
Cancel
Save