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 Framework开发者_如何学编程ElementFactory 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.
精彩评论