Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Samples/Samples/View/ClipboardPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Entry Placeholder="Enter text..." Text="{Binding FieldValue}" />
<Button Text="Copy to clipboard" Command="{Binding CopyCommand}" />
<Button Text="Paste from clipboard" Command="{Binding PasteCommand}" />
<Button Text="Check Status" Command="{Binding CheckCommand}" />
<Label Text="{Binding LastCopied}" />
</StackLayout>
</ScrollView>
Expand Down
8 changes: 8 additions & 0 deletions Samples/Samples/ViewModel/ClipboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ public ClipboardViewModel()
{
CopyCommand = new Command(OnCopy);
PasteCommand = new Command(OnPaste);
CheckCommand = new Command(OnCheck);
}

public ICommand CopyCommand { get; }

public ICommand PasteCommand { get; }

public ICommand CheckCommand { get; }

public string FieldValue
{
get => fieldValue;
Expand Down Expand Up @@ -72,5 +75,10 @@ async void OnPaste()
FieldValue = text;
}
}

async void OnCheck()
{
await DisplayAlertAsync($"Has text: {Clipboard.HasText}");
}
}
}
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Clipboard/Clipboard.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static Task PlatformSetTextAsync(string text)
}

static bool PlatformHasText
=> Platform.ClipboardManager.HasPrimaryClip;
=> Platform.ClipboardManager.HasPrimaryClip && !string.IsNullOrEmpty(Platform.ClipboardManager.PrimaryClip?.GetItemAt(0)?.Text);

static Task<string> PlatformGetTextAsync()
=> Task.FromResult(Platform.ClipboardManager.PrimaryClip?.GetItemAt(0)?.Text);
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Clipboard/Clipboard.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static Task PlatformSetTextAsync(string text)
static NSObject observer;

static bool PlatformHasText
=> UIPasteboard.General.HasStrings;
=> UIPasteboard.General.HasStrings && !string.IsNullOrEmpty(UIPasteboard.General.String);

static Task<string> PlatformGetTextAsync()
=> Task.FromResult(UIPasteboard.General.String);
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Clipboard/Clipboard.macos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static Task PlatformSetTextAsync(string text)
}

static bool PlatformHasText =>
GetPasteboardText() != null;
!string.IsNullOrEmpty(GetPasteboardText());

static Task<string> PlatformGetTextAsync()
=> Task.FromResult(GetPasteboardText());
Expand Down