4

我正在使用 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));

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

4

1 回答 1

9

我得到了答案。这是

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

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

于 2011-09-07T08:09:24.873 回答