0
votes

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. 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.....

1
This is the expected behaviour and how popups work. The "steal" the focus so you have to first close it and then click on any button.mm8

1 Answers

0
votes

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;
    }
}