我有一个 Xceed (Xceed.Wpf.Toolkit) 子窗口,我正在我的 WPF 窗口的代码后面创建它,它的工作方式符合我的预期。
private void CustomerNotesPopup(string text, string caption)
{
TextBlock tbCustomerNotes = new TextBlock()
{
Text = text,
Margin = new Thickness(10),
TextWrapping = TextWrapping.Wrap,
FontSize = 20
};
Button btnConfirm = new Button()
{
Width = 150,
FontWeight = FontWeights.Bold,
Height = 59,
Content = "Confirm",
FontSize = 22,
Background = Brushes.Black,
Foreground = Brushes.White,
BorderBrush = Brushes.Black
};
btnConfirm.Click += btn_Click;
StackPanel sp = new StackPanel()
{
Orientation = Orientation.Vertical,
Margin = new Thickness(5)
};
sp.Children.Add(tbCustomerNotes);
sp.Children.Add(btnConfirm);
Xceed.Wpf.Toolkit.ChildWindow pop = new Xceed.Wpf.Toolkit.ChildWindow()
{
Height = 550,
Width = 550,
IsModal = true,
Content = sp,
WindowStartupLocation = Xceed.Wpf.Toolkit.WindowStartupLocation.Center,
Caption = caption,
Name = "PopUpWindow"
};
cgcanvas.Children.Add(pop);
pop.Show();
}
现在我正在尝试连接 btnConfirm.Click += btn_Click; 单击按钮时关闭弹出窗口的事件。我尝试了几种不同的方法来查找 Xceed Child 名称并将其关闭,但无法找到该名称并按命令将其关闭。
我想我对此很接近,但到目前为止我还没有弄清楚如何在代码中获取和关闭它。
private void btn_Click(object sender, RoutedEventArgs e)
{
//foreach (Xceed.Wpf.Toolkit.ChildWindow popwindow in Application.Current.Windows)
//{
// //if (window.Name == "PopUpWindow")
// //{
// // window.Close();
// popwindow.Close();
// //}
//}
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(cgcanvas); i++)
{
var nameCheck = VisualTreeHelper.GetChild(cgcanvas, i) as Xceed.Wpf.Toolkit.ChildWindow;
//if (nameCheck.Name == "PopUpWindow")
//{
// MessageBox.Show("Yes");
//}
}
}