WPF - 在父级中处理特定控件实例的 RoutedEvent

发布于 2024-09-05 02:32:46 字数 379 浏览 0 评论 0原文

在我的用户控件中,我有几个文本框,例如 Textbox1、Textbox2。

在父级中,我只想处理从 Textbox1 引发的 KeyDown 事件,并非所有 Textbox

我都在父级中添加了处理程序

this.AddHandler(TextBox.KeyDownEvent, new RoutedEventHandler(OnTextboxGoToPageKeyDown));

,但当然这将处理我不想要的所有 KeyDown 事件。

我是否必须在 RoutedEventHandler 中添加一些条件逻辑来检查事件的引发位置?

或者有更好的方法吗?

最好的方法是什么?

谢谢。

In my user control I have several textboxes e.g. Textbox1, Textbox2.

In the parent I only want to handle KeyDown events raised from Textbox1, not all Textbox

I have added a handler in the parent

this.AddHandler(TextBox.KeyDownEvent, new RoutedEventHandler(OnTextboxGoToPageKeyDown));

but of course this will handle all KeyDown events which I don't want.

Do I have to add some conditional logic in the RoutedEventHandler to check where the event was raised from?

or is there a better way?

What's the best way to do this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高速公鹿 2024-09-12 02:32:46

OnTextboxGoToPageKeyDown 中的 RoatedEventArgs 有一个名为 Source 的属性,该属性包含对引发事件的对象的引用。当您需要执行逻辑时,您可以请求该属性。

华泰

The RoutedEventArgs in your OnTextboxGoToPageKeyDown has a property named Source which have a references to the Object who raised the event. You can ask for that property when you need to execute your logic.

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文