Tuesday, January 13, 2009

How to intercept a copy or paste operation

I've just found these static methods on the System.Windows.DataObject class.
DataObject.AddPastingHandler(dependencyObject, handler);
DataObject.RemovePastingHandler(dependencyObject, handler);

DataObject.AddCopyingHandler(dependencyObject, handler);
DataObject.RemovePastingHandler(dependencyObject, handler);

DataObject.AddSettingDataHandler(dependencyObject, handler);
DataObject.RemoveSettingDataHandler(dependencyObject, handler);
Very useful!!

You can use these to inspect an object before it is pasted/copied/drag-dropped and change the course of the action by doing stuff like Cancel or Change Format.



No comments: