microsoft / microsoft/microsoft-ui-xaml
UI offset issue after minimizing and reopening WinUI 3 window with restore disabled
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
In a WinUI 3 application, when the window’s restore button is disabled and the app is minimized and then reopened, the UI appears to shift downward.
**Steps to reproduce:**
1. Create a WinUI 3 window.
2. Disable the restore button and resizing.
3. Run the app.
4. Minimize the window.
5. Reopen it.
**Expected behavior:**
The UI layout should remain unchanged when minimized and reopened.
**Actual behavior:**
The entire UI content shifts downward after reopening.
I have two pages. The main page includes a button that navigates to the second page. When navigating, the second page should display in full window mode, and the restore button is disabled. However, when the app is minimized and then reopened, the UI appears shifts downward. What could be causing this problem?
**MainWindow.xaml**
```
```
**MainWindow.xaml.cs**
```
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
namespace App1
{
public sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ContentFrame.Navigated += ContentFrame_Navigated;
ContentFrame.Navigate(typeof(MainPage), this);
}
private void ContentFrame_Navigated(object sender, Microsoft.UI.Xaml.Navigation.NavigationEventArgs e)
{
var appWindow = GetAppWindowForCurrentWindow();
if (appWindow != null && appWindow.Presenter is OverlappedPresenter presenter)
{
if (e.SourcePageType == typeof(SecondPage))
{
// On second page: maximize and disable resizing
presenter.Maximize();
presenter.IsMaximizable = false;
presenter.IsResizable = false;
}
else
{
// On main page: enable resizing
presenter.IsMaximizable = true;
presenter.IsResizable = true;
}
}
}
public void NavigateToSecondPage()
{
ContentFrame.Navigate(typeof(SecondPage));
}
public AppWindow? GetAppWindowForCurrentWindow()
{
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(windowId);
}
}
}
```
**MainPage.xaml**
```
```
**MainPage.xaml.cs**
```
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
namespace App1
{
public sealed partial class MainPage : Page
{
private MainWindow? _mainWindow;
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (e.Parameter is MainWindow mainWindow)
{
_mainWindow = mainWindow;
}
}
private void OpenSecondPageBtn_Click(object sender, RoutedEventArgs e)
{
_mainWindow?.NavigateToSecondPage();
}
}
}
```
**SecondPage.xaml**
```
```
**SecondPage.xaml.cs**
```
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace App1
{
public sealed partial class SecondPage : Page
{
public SecondPage()
{
InitializeComponent();
}
private void BackBtn_Click(object sender, RoutedEventArgs e)
{
if (Frame.CanGoBack)
{
Frame.GoBack();
}
}
}
}
```
**Before**
**After (App is minimized then reopened)**
Contributor guide
Research direction
Reproduce the behavior with the provided MainWindow.xaml, MainWindow.xaml.cs, MainPage.xaml.cs, and SecondPage.xaml.cs sample. Start by tracing ContentFrame_Navigated and the minimize/reopen sequence while the OverlappedPresenter is maximized and non-resizable. Done means identifying the cause of the downward layout shift and documenting or validating a framework-level correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100