gpt4 book ai didi

.net - PresentationCore.dll 中发生“System.StackOverflowException”

转载 作者:行者123 更新时间:2023-12-03 18:30:12 25 4
gpt4 key购买 nike

我有一个 WPF UserControl,我尝试在其中实现 定制 MouseClick(因为 WPF(用户)控件上没有 MouseClick 事件)事件。

我得到以下信息:

alt text

一些代码:

/// <summary>
/// Occurs when users left clicks the MyControl.
/// </summary>
public event MouseButtonEventHandler MouseClick { add { AddHandler(MouseClickEvent, value); } remove { RemoveHandler(MouseClickEvent, value); } }

protected virtual void OnMouseClick(MouseButtonEventArgs e)
{
base.RaiseEvent(e);
//this.RaiseEvent(new RoutedEventArgs(MouseClickEvent, this));
}

protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
if (!this.movedAfterMouseDown)
{
OnMouseClick(e);
}
this.gotLeftButtonDown = false;
this.movedAfterMouseDown = false;
}

那么,问题出在哪里呢?

更新 1
protected virtual void OnMouseClick(MouseButtonEventArgs e)
{
//base.RaiseEvent(e);
MouseButtonEventArgs args = new MouseButtonEventArgs(e.MouseDevice, e.Timestamp, e.ChangedButton);
this.RaiseEvent(args);
}

值不能为空。
参数名称:routedEvent

alt text

更新 2

我成功实现的另一个自定义事件(工作没有问题)- SelectedChanged :
static void OnIsSelectedChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
var s = (MyControl)source;

s.RaiseEvent(new RoutedEventArgs(SelectedChangedEvent, s));
}

更新 3

System.Windows.Controls.Control 的 OnPreviewMouseDoubleClick 实现:
protected virtual void OnPreviewMouseDoubleClick(MouseButtonEventArgs e)
{
base.RaiseEvent(e);
}

更新 5(对于坦克中的人)
class Foo : FrameworkElement
{
event EasterCameEvent; // I named it MouseClick

public DoSomething()
{
EasterCameArgs args= ...

if (Date.Now = EasterDate)
OnEasterCame(args)
}

protected virtual void OnEasterCame(EasterCameArgs e)
{
base.RaiseEvent(e);
}
}

最佳答案

protected virtual void OnMouseClick(MouseButtonEventArgs e)
{
MouseButtonEventArgs args = new MouseButtonEventArgs(e.MouseDevice, e.Timestamp, e.ChangedButton);

// Don't forget this
args.RoutedEvent = MouseClickEvent;

base.RaiseEvent(args);
}

关于.net - PresentationCore.dll 中发生“System.StackOverflowException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4235749/

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