c# - WPF FrameworkElementFactory 图像创建无法为 MouseDownEvent 添加处理程序

标签 c# wpf binding wpf-controls frameworkelementfactory

我正在使用 Framework ElementFactory 在 DataTemplate 中创建图像。尝试处理 Image 类型的 MouseDown 事件时,抛出异常 - “Handler Type is not valid.

我们如何为 Image 类型的 FrameworkElementFactory 添加 MouseDownEventHandler

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));

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

最佳答案

我得到了答案。这是

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

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

关于c# - WPF FrameworkElementFactory 图像创建无法为 MouseDownEvent 添加处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7330428/

相关文章:

c# - 以编程方式创建 'SharePoint Solution'

c# - 在 C# 中使用 'DefaultAudioEndpoint' 以外的音频端点

c# - 在filter mvvm c# wpf的基础上自定义wpf折线图的x轴

c# - 在位图图像中设置背景颜色

c++ - 获取第三方Click-Once应用的config文件夹

c# - 从自定义控件绑定(bind)到 ObservableCollection

c# - 在 textchanged 上禁用 c# 中的事件处理程序

WPF:使用哪个集合类

java静态绑定(bind)和多态性

c# - 设置字段 DateTime 以 dd/mm/yyyy hh :mm:ss 格式显示日期和时间