This repository was archived by the owner on May 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +12
-3
lines changed
Xamarin.Essentials/Clipboard Expand file tree Collapse file tree 5 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 17
17
<Entry Placeholder =" Enter text..." Text =" {Binding FieldValue}" />
18
18
<Button Text =" Copy to clipboard" Command =" {Binding CopyCommand}" />
19
19
<Button Text =" Paste from clipboard" Command =" {Binding PasteCommand}" />
20
+ <Button Text =" Check Status" Command =" {Binding CheckCommand}" />
20
21
<Label Text =" {Binding LastCopied}" />
21
22
</StackLayout >
22
23
</ScrollView >
Original file line number Diff line number Diff line change @@ -14,12 +14,15 @@ public ClipboardViewModel()
14
14
{
15
15
CopyCommand = new Command ( OnCopy ) ;
16
16
PasteCommand = new Command ( OnPaste ) ;
17
+ CheckCommand = new Command ( OnCheck ) ;
17
18
}
18
19
19
20
public ICommand CopyCommand { get ; }
20
21
21
22
public ICommand PasteCommand { get ; }
22
23
24
+ public ICommand CheckCommand { get ; }
25
+
23
26
public string FieldValue
24
27
{
25
28
get => fieldValue ;
@@ -72,5 +75,10 @@ async void OnPaste()
72
75
FieldValue = text ;
73
76
}
74
77
}
78
+
79
+ async void OnCheck ( )
80
+ {
81
+ await DisplayAlertAsync ( $ "Has text: { Clipboard . HasText } ") ;
82
+ }
75
83
}
76
84
}
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ static Task PlatformSetTextAsync(string text)
17
17
}
18
18
19
19
static bool PlatformHasText
20
- => Platform . ClipboardManager . HasPrimaryClip ;
20
+ => Platform . ClipboardManager . HasPrimaryClip && ! string . IsNullOrEmpty ( Platform . ClipboardManager . PrimaryClip ? . GetItemAt ( 0 ) ? . Text ) ;
21
21
22
22
static Task < string > PlatformGetTextAsync ( )
23
23
=> Task . FromResult ( Platform . ClipboardManager . PrimaryClip ? . GetItemAt ( 0 ) ? . Text ) ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ static Task PlatformSetTextAsync(string text)
16
16
static NSObject observer ;
17
17
18
18
static bool PlatformHasText
19
- => UIPasteboard . General . HasStrings ;
19
+ => UIPasteboard . General . HasStrings && ! string . IsNullOrEmpty ( UIPasteboard . General . String ) ;
20
20
21
21
static Task < string > PlatformGetTextAsync ( )
22
22
=> Task . FromResult ( UIPasteboard . General . String ) ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ static Task PlatformSetTextAsync(string text)
22
22
}
23
23
24
24
static bool PlatformHasText =>
25
- GetPasteboardText ( ) != null ;
25
+ ! string . IsNullOrEmpty ( GetPasteboardText ( ) ) ;
26
26
27
27
static Task < string > PlatformGetTextAsync ( )
28
28
=> Task . FromResult ( GetPasteboardText ( ) ) ;
You can’t perform that action at this time.
0 commit comments