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

查看:97
本文介绍了从.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 链接

You need a RoutedEvent link

"路由事件是在可视树中向上或向下导航的事件 根据他们的RoutingStrategy.路由策略可以是泡沫, 隧道或直接.您可以将事件处理程序连接到 通过使用引发事件或在事件之上或之下的其他元素上 附加的事件语法: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天全站免登陆