I have an Xceed (Xceed.Wpf.Toolkit) Child window that I am creating in my WPF Window's Code Behind, which is working the way I would expect.
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();
}
Now I am trying to wire up the btnConfirm.Click += btn_Click; event to close the pop up when the button is clicked. I have tried several different methods of finding the Xceed Child name and closing it but haven't been able to find the name and close it on command.
I think I am close with this but so far I still haven't figure out how to get and close it in code.
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");
//}
}
}