我设计了一个UserControl,并计划在MainWindow中单击按钮时将其显示为弹出窗口。
我按照这个链接的方法来打开usercontrol作为对话框窗口。
private void btnInstApp_Click(object sender, RoutedEventArgs e)
{
Window objWindow = new Window
{
Title = "Title 12345",
WindowStyle = WindowStyle.None,
WindowStartupLocation = WindowStartupLocation.CenterScreen,
AllowsTransparency=true,
Width = 500,
Height = 200,
Content = new ucInstrumentApp()
};
objWindow.ShowDialog();
}
我使用None
作为WindowStyle
,并在UserControl中设计了一个自定义关闭按钮来关闭弹出/对话框窗口。我尝试了下面提供的代码,但它不起作用。
private void btnClose_Click(object sender, RoutedEventArgs e)
{
//this.Close(); //:not working
Window objWindow = new Window
{
Content = new ucInstrumentApp()
};
objWindow.Close();
}
我是WPF/Windows Forms的新手,你们能指导我解决这个问题吗?