开发者

WPF FrameworkElementFactory Image creation Not able to AddHandler for MouseDownEvent

开发者 https://www.devze.com 2023-04-03 08:47 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消