Raising an event on parent window from a user control in .NET C#(从 .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# 中的用户控件在父窗口上引发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 .NET C# 中的用户控件在父窗口上引发事件
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
