4

DataTemplate で画像を作成するために Framework ElementFactory を使用しています。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 に答える