Creating WPF Image FrameworkElementFactory Cannot AddHandler for MouseDownEvent

I am using Framework ElementFactory to create an image in a DataTemplate. When trying to process the MouseDown event for the image type, an exception was thrown - "The type of handler is invalid.

How can we add a MouseDownEventHandler for a FrameworkElementFactory of type Image

FrameworkElementFactory imageSecondaryContent = new FrameworkElementFactory(typeof(Image)); imageSecondaryContent.SetValue(Image.WidthProperty, imgWidth); imageSecondaryContent.SetValue(Image.VisibilityProperty, Visibility.Hidden); imageSecondaryContent.Name = imageName; Binding tmpBindingSecondaryContent = new Binding(); tmpBindingSecondaryContent.Source = IconLibary.GetUri(IconStore.ExclaminationPoint); imageSecondaryContent.SetBinding(Image.SourceProperty, tmpBindingSecondaryContent); imageSecondaryContent.AddHandler(Image.MouseDownEvent, new RoutedEventHandler(Test)); 

The last line throws an exception. Please, help

+4
source share
1 answer

I got an answer.

 imageSecondaryContent.AddHandler(Image.MouseDownEvent, new MouseButtonEventHandler(Test)); 

Please close the question if you think you need to close it.

+9
source

All Articles