Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF FrameworkElementFactory Image creation Not able to AddHandler for MouseDownEvent

I am using Framework ElementFactory for creating a image in DataTemplate. While trying to handle the MouseDown Event for the Image type, an exception is thrown - "Handler Type is not valid.

How can we add an MouseDownEventHandler for the 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

like image 266
ganeshran Avatar asked Jan 19 '23 19:01

ganeshran


1 Answers

I got the answer. It is

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

Please close the question if you think it needs to be closed.

like image 90
ganeshran Avatar answered Jan 21 '23 11:01

ganeshran