WPF FrameworkElementFactory 图像创建无法为 MouseDownEvent 添加处理程序
我正在使用 Framework ElementFactory 在 DataTemplate 中创建图像。在尝试处理 Image 类型的 MouseDown 事件时,抛出异常 - “Handler Type is not valid.
How can we add an MouseDownEventHandler for the FrameworkElementFactory of type Image
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));
最后一行抛出异常。请帮助
I am using Framework ElementFactory for creating a image in DataTemplate. While trying to handle the MouseDown Event for the Image type, an exception is thrown - "Handler Type is not valid.
How can we add an MouseDownEventHandler for the FrameworkElementFactory of type Image
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));
The last line throws an exception. Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了答案。 。
如果您认为需要关闭问题,请关闭该问题
I got the answer. It is
Please close the question if you think it needs to be closed.