如何查找和代码关闭一个xceed子窗口的后面

问题描述 投票:0回答:1

我有我在我的WPF窗口的代码正在创建后面的Xceed(Xceed.Wpf.Toolkit)子窗口,这是工作我希望的方式。

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儿童的姓名和关闭它的几种不同的方法,但一直没能找到名字和关闭它的命令。

我想我靠近这个,但到目前为止我还没有弄清楚如何获得并在代码中关闭它。

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# wpf code-behind
1个回答
0
投票

通过使用由鲍勃在评论中提供的建议,我是能够注册和查找Xceed弹出窗口的名称。我结束了本身将代码块中的一个类文件,并不需要登记后所有。不过,我也不会去到没有暗示这一点。

要完成我用Find all controls in WPF Window by type找到父的Xceed控制,然后由它的名字将其关闭淘汰任务。

© www.soinside.com 2019 - 2024. All rights reserved.