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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With