dotnet / dotnet/wpf

While changing a Window size will execute the other events of wpf.

Open
#4,925 1 comment 1 reaction 0 assignees View on GitHub
.NET Framework
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 5.0.201
* Windows version: 20H2
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

**Problem description:**
When I execute the `WindowState = WindowState.Maximized`, I found some events are executed before the `WindowState = WindowState.Maximized` return. This will break the time sequence of application, please check this.
And I also found that not only the ShowWindow API, like SetWindowPos API also will cause this problem.
I guess these API cause the System to post some messages to the application like LocationChanged or SizeChanged, and at this moment cause Dispatcher to execute the current remain DispatchOperation?

The code is here:
```
private void Button_Click(object sender, RoutedEventArgs e)
{
TestBtn.Unloaded += (sender, e) =>
{
Debug.WriteLine("TestBtn_Unloaded");
};
ButtonGrid.Children.Remove(TestBtn);

Debug.WriteLine("Before Maximized");
WindowState = WindowState.Maximized;
Debug.WriteLine("After Maximized");
}
```
The output is here:
```
Before Maximized
TestBtn_Unloaded
After Maximized
```

**Actual behavior:**
Execute the other event in the current thread while executing some Window operations.

**Expected behavior:**
Do not execute the other event in the current thread.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.