界面1内设定点击事件,生成Path用事件传出
public partial class TemplateWindow : Window
{
internal delegate void ConfirmButtonClick(string Path);
/// <summary>
/// 点击确定按钮事件
/// </summary>
internal event ConfirmButtonClick OnConfirmButtonClick;
private void ConfirmButton_Click(object sender, RoutedEventArgs e)
{
string Path = “C://User//Path”;
if (null != this.OnConfirmButtonClick)
{
this.OnConfirmButtonClick(Path);
}
this.Close();
}
}
界面二通过事件获取界面1的Path
public partial class User : UserControl
{
private void ShowWindow_Click(object sender, RoutedEventArgs e)
{
TemplateWindow window = new TemplateWindow ();
window.Show();
window.OnConfirmButtonClick += (Path) =>
{
Console.Writeline(Path);
};
}
}
原文地址:https://www.cnblogs.com/kid526940065/p/8516077.html
时间: 2024-11-05 15:57:25