wpf
wpf copied to clipboard
Expose typed Clipboard APIs in WPF
As the Windows clipboard is a shared resource and .NET uses binary format (NRBF), there is some amount of risk to having only untyped (object) deserialization. While usage of BinaryFormatter now requires a compatibility package, when one needs to take this dependency for Clipboard or other reasons there are ways to mitigate exposure here.
New Clipboard and DataObject APIs describes the new set of APIs and behaviors that both Windows Forms and WPF are implementing in .NET 10.
The brief summary of changes:
GetAPIs that returnobjectare all obsoleted- A new
TryGet<T>set of methods have been introduced to replace the obsoleted APIs - Introduces a
SetDataAsJson<T>for simple JSON user type serialization BinaryFormatterusage in Clipboard scenarios now requires an additionalAppContextswitch
It is recommended that users use .NET primitive types (string, int, etc.) or arrays or List<> of these primitives for Clipboard and drag/drop. Simple types can be set with SetDataAsJson to avoid BinaryFormatter.
Checklist of required work:
- [x] Consume and use shared OLE implementation from WinForms #10544
- [x] Expose typed get and set as JSON APIs #10544
- [ ] Obsolete old APIs
- [ ] Null annotate new APIs in ref assembly
- [ ] Create breaking change documentation
- [ ] Update API documentation
Checklist for other follow-up:
- [ ] Implement additional unit tests
- [ ] Convert drag/drop code to use shared implementation
- [ ] Investigate removing hard dependency of System.Drawing.Common for Clipboard
And updates on the index parameter?
Is TryGet<T> with T being object compatible with the deprecated APIs?