界面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)
界面二通过事件获取界面1的Path
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)
private void ShowWindow_Click(object sender, RoutedEventArgs e)
{
TemplateWindow window = new TemplateWindow ();
window.Show();
window.OnConfirmButtonClick += (Path) =>
{
Console.Writeline(Path);
};
}
}