Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enumerate the clipboard formats

Tags:

clipboard

wpf

With WPF, I can get data in a given format from the clipboard:

object test = Clipboard.GetGata (format);

How can I enumerate the list of formats present in the clipboard?

like image 677
user380719 Avatar asked Jan 28 '26 16:01

user380719


2 Answers

Have a look at IDataObject:

IDataObject content = Clipboard.GetDataObject();
string[] formats = content.GetFormats();
like image 154
Jf Beaulac Avatar answered Jan 31 '26 00:01

Jf Beaulac


 List<String> dataFormats = typeof(DataFormats).GetFields(BindingFlags.Public | BindingFlags.Static)
                                .Select(f => f.Name)
                                .ToList();

this should give you all the Fields from DataFormats

List<String> dataFormatsInClipboard = 
             dataFormats.Where( df => Clipboard.ContainsData(df) )
             .ToList();

will give you just the ones that match the clipboard.

like image 41
Bala R Avatar answered Jan 31 '26 01:01

Bala R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!