首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF FrameworkElementFactory映像创建无法对MouseDownEvent执行AddHandler操作

WPF FrameworkElementFactory映像创建无法对MouseDownEvent执行AddHandler操作
EN

Stack Overflow用户
提问于 2011-09-07 15:43:23
回答 1查看 2.2K关注 0票数 4

我正在使用框架ElementFactory在DataTemplate中创建图像。当尝试处理图像类型的MouseDown事件时,抛出异常-“处理程序类型无效。

如何为类型为FrameworkElementFactory的图像添加MouseDownEventHandler

代码语言:javascript
复制
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));

最后一行抛出一个异常。请帮帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-07 16:09:25

我知道答案了。它是

代码语言:javascript
复制
imageSecondaryContent.AddHandler(Image.MouseDownEvent, new MouseButtonEventHandler(Test));

如果您认为需要关闭该问题,请关闭该问题。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7330428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档