gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:27:14 30 4
gpt4 key购买 nike

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

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com