[英]When popup is opened and try to close the main window, It closes only popup not main window
I am having a button called 'bookmarks'. 我有一个名为“书签”的按钮。 To show the bookmarks I have used the popup.
为了显示书签,我使用了弹出窗口。 when I clicked on the button called 'bookmarks' the popup is opened and If I clicked on any other button let say, 'Play' which is on the main window should play the video and closes the popup as well.
当我单击名为“书签”的按钮时,将打开弹出窗口,如果单击任何其他按钮,请说,主窗口中的“播放”应播放视频并关闭弹出窗口。 this all is working fine but the problem is ===> When I try to minimize or close the main window, It closes the popup only not the main window.
这一切工作正常,但问题是===>当我尝试最小化或关闭主窗口时,它仅关闭弹出窗口而不关闭主窗口。 in short, I need to hit the close button twice for closing the main window while the popup is opened.
简而言之,在弹出窗口打开时,我需要按两次关闭按钮以关闭主窗口。
The code sample that I have used 我使用的代码示例
public void Show(object viewModel, string title, double width, double height)
{
m_popup = new Popup();
m_popup.AllowsTransparency = true;
m_popup.StaysOpen = false;
m_popup.IsOpen = true;
m_popup.PlacementRectangle = new Rect(App.Current.MainWindow.Left + 570, App.Current.MainWindow.Top + 60, 0, 0);
m_popup.VerticalOffset = 20;
ContentControl contentControl = new ContentControl();
contentControl.Content = viewModel;
m_popup.Child = contentControl;
m_popup.Closed += Popup_Closed;
IsActive = true;
}
private void Popup_Closed(object sender, EventArgs e)
{
IsActive = false;
}
Note: please ignore IsActive property. 注意:请忽略IsActive属性。 I have used that for another purpose.
我已经将其用于其他目的。
I had tried Modal dialog by setting the main window as an owner but It was not useful because I want the main window to be interactive while the popup is opened. 我曾尝试通过将主窗口设置为所有者来尝试“模态”对话框,但是它没有用,因为我希望在打开弹出窗口时主窗口是交互式的。 please suggest me the solution.
请给我建议解决方案。
Thanks..... 谢谢.....
It looks like you need non-modal child window instead of popup: 看来您需要非模式子窗口而不是弹出窗口:
public partial class MainWindow : Window
{
// FloatingWindow is just a window descendant
private FloatingWindow floatingWindow;
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (floatingWindow == null)
{
floatingWindow = new FloatingWindow();
floatingWindow.Owner = this;
floatingWindow.Closed += FloatingWindow_Closed;
}
floatingWindow.Show();
floatingWindow.Activate();
}
private void FloatingWindow_Closed(object sender, EventArgs e)
{
floatingWindow = null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.