如何在父级中定义的用户控件中注册事件

本文关键字:用户 控件 注册 事件 定义 | 更新日期: 2023-09-27 17:57:06

我有:

A.xaml
A.xaml.cs

MyuserControl.xaml
MyuserControl.xaml.cs

在我创建<MyuserControl x:Name="MyuserControl" />的 xaml 中in MyuserControl DataGrid

我需要在 A.xaml.cs 中注册事件DataGrid.SelectionChanged和描述。

public void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e){}

我需要添加事件在 XAML 中这是怎么做到的?

如何在父级中定义的用户控件中注册事件

在 A 中很好.xml.cs

例如,您可以在构造函数中这样做:

MyUserControl.DataGrid.SelectionChanged += new .....(DataGrid_SelectionChanged);

谢谢亚历克斯。