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