我使用CodePlex DLL创建了MDI表单,添加了一个WPF用户控件,并将其作为子控件打开,代码如下:
MainMdiContainer.Children.Add(new MdiChild()
{
Title = " Employee Master",
Height = 300,
Width = 500,
//Here CustomerMaster is the class that you have created for mainWindow.xaml user control.
Content = new EmpMaster()
});现在,我只想在单击按钮时关闭该子窗体(WPF用户控件),我在该按钮单击时使用了以下代码:
Window.GetWindow(this).Close();但是,这段代码也关闭了程序,同时关闭了所有打开的窗口和MDI父程序。如何在单击按钮时只关闭特定的WPF用户控件?
发布于 2015-08-18 11:54:29
我得到了答案,我已经调用了下面的代码行,按一下按钮:
MainWindow mainWind = Application.Current.MainWindow as MainWindow;
mainWind.MainMdiContainer.Children.RemoveAt(0);发布于 2015-08-18 07:47:34
我不知道这个框架,但我怀疑MDI子结构不是Window。调用Window.GetWindow(this).Close();时,关闭主窗口,从而终止应用程序。
尝试从MdiChild中删除MainMdiContainer
var child = new MdiChild() { ... };
MainMdiContainer.Children.Add(child);
// Later
MainMdiContainer.Children.Remove(child);https://stackoverflow.com/questions/32066225
复制相似问题