我正在使用 Framework ElementFactory 在 DataTemplate 中创建图像。尝试处理 Image 类型的 MouseDown 事件时,抛出异常 - “处理程序类型无效。
我们如何为 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));
最后一行抛出异常。请帮忙