0

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");
        //}
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Buck Hicks
  • 1,534
  • 16
  • 27
  • 1
    Have a look at [Why can't I access a TextBox by Name with FindName?](http://stackoverflow.com/questions/1755377/why-cant-i-access-a-textbox-by-name-with-findname) – Bob. Nov 11 '13 at 15:53
  • Thank you that helped me get to the final answer – Buck Hicks Nov 11 '13 at 17:00

1 Answers1

0

By using the suggestion provided by Bob in the comments I was able to register and find the name of Xceed pop up window. I ended up putting the code block in a class file by itself so the register wasn't needed after all. However, I wouldn't have made it to that point without the suggestion.

To finish the task I used Find all controls in WPF Window by type to find the Xceed control on the parent and then close it out by its name.

Community
  • 1
  • 1
Buck Hicks
  • 1,534
  • 16
  • 27