How to raise an attached event in wpf?

How can I raise a DataObject.Pasting event from my code?

+3
source share
2 answers

You can raise any event on any UIElementusing the method RaiseEvent(). Just create the appropriate event arguments for the handler and go to RaiseEvent().

var args = new DataObjectPastingEventArgs(dataObject, isDragDrop, formatToApply)
{
    Source = this,
    RoutedEvent = DataObject.PastingEvent //set the event here
};
element.RaiseEvent(args);
+4
source

You need to call RaiseEvent in the corresponding UIElement, passing RoutedEventArgs with the RoutedEvent parameter set to DataObject.Pasting.

+1
source

Source: https://habr.com/ru/post/1760479/


All Articles