从 .NET C# 中的用户控件在父窗口上引发事件 [英] Raising an event on parent window from a user control in .NET C#

查看:13
本文介绍了从 .NET C# 中的用户控件在父窗口上引发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题几乎解释了这个问题.首次运行应用程序时,我将用户控件加载到主窗口中.我想要做的是在单击用户控件上的按钮时在父窗口上引发事件,那么如何从用户控件上的 button1_Click 引发父事件?

The title pretty much explains the question. I have a user control loaded into the main window when the application is first run. What I want to do is to raise an event on parent window when a button on the user control is clicked, so how can I raise a parent event from button1_Click on the user control?

推荐答案

你需要一个 RoutedEvent link

You need a RoutedEvent link

路由事件是在可视化树中向上或向下导航的事件根据他们的路由策略.路由策略可以是冒泡的,隧道或直接.您可以在元素上连接事件处理程序通过使用引发事件或在其上方或下方的其他元素上附加的事件语法:Button.Click="Button_Click"."

"Routed events are events which navigate up or down the visual tree acording to their RoutingStrategy. The routing strategy can be bubble, tunnel or direct. You can hook up event handlers on the element that raises the event or also on other elements above or below it by using the attached event syntax: Button.Click="Button_Click"."

这篇关于从 .NET C# 中的用户控件在父窗口上引发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆