Skip to content

window events are invalid and cannot be closed or clicked #11086

@hzh1993

Description

@hzh1993

Description

The non-modal window is closed as the owner. Other window events are invalid and cannot be closed or clicked.

Reproduction Steps

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    Window1 window = null;
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        window = new Window1();
        window.Show();
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        Window1 window2 = new Window1();
        window2.Owner = window;

        Task.Run(() => {
            Thread.Sleep(3000);
            System.Windows.Application.Current.Dispatcher.BeginInvoke((System.Action)(() =>
            {
                window.Close();  //Causes other window events to invalid
            }));
        });

        window2.ShowDialog();
    }
}

Expected behavior

Works properly

Actual behavior

Causes other window events to invalid

Regression?

This problem exists testing with .Net 5 or .Net 9

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugProduct bug (most likely)InvestigateRequires further investigation by the WPF team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions