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# 中的用户控件在父窗口上引发事件


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01