子頁面:
public partial class MyPopupWindow : Window
{
? ? public event Action OnClose;
?
? ? private void CloseWindowButton_Click(object sender, RoutedEventArgs e)
? ? {
? ? ? ? OnClose?.Invoke();
? ? ? ? this.Close();
? ? }
}
主界面:
public partial class MainWindow : Window
{
? ? public MainWindow()
? ? {
? ? ? ? InitializeComponent();
? ? ? ? MyPopupWindow popup = new MyPopupWindow();
? ? ? ? popup.OnClose += RefreshUI;
? ? ? ? popup.Show();
? ? }
?
? ? private void RefreshUI()
? ? {
? ? ? ? // 更新UI的代碼,例如:
? ? ? ? this.DataContext = GetUpdatedData(); // 假設GetUpdatedData返回更新后的數據對象
? ? }
}
來源:百度Ai