microsoft / microsoft/microsoft-ui-xaml

Mica get's overdrawn by Swapchain when Swapchain covers entire screen

Open
#10,180 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Materials bug team-Core team-Rendering
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

Consider the following scenario where we create a CanvasSwapchainPanel from Win2D while the Window has Mica as backdrop:

```xaml





```

```c#
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}

CanvasSwapChain csc;

private void Swappy_SizeChanged(object sender, SizeChangedEventArgs e)
{
this.csc = new CanvasSwapChain(CanvasDevice.GetSharedDevice(), Math.Max((float)Swappy.ActualWidth, 1), Math.Max((float)Swappy.ActualHeight, 1), 96);
this.Swappy.SwapChain = this.csc;
DrawInPanel();
}

private void DrawInPanel()
{
using (var ds = this.csc.CreateDrawingSession(Microsoft.UI.Colors.Transparent))
{
ds.Clear(Microsoft.UI.Colors.Transparent);
ds.DrawText("Some text", 0, 0, Microsoft.UI.Colors.Red);
ds.DrawRectangle(0, 0, 100, 100, Microsoft.UI.Colors.Red);
}
this.csc.Present(0);
}
}
```

With this, the output looks like this:
![Screenshot of black window](https://github.com/user-attachments/assets/43606a69-1cd5-4aa7-918a-273175e8848c)

However if we change the Grid or the CanvasSwapChainPanel to have a margin or padding of 1 in any of the directions, like this:
```XAML
[...]

[...]
```
Mica works:
![Screenshot of Mica working](https://github.com/user-attachments/assets/3fef990a-4576-4d18-adb8-c51f9e7b6226)

To add to the unusualness, when one sets the margin and padding of the Grid and CSCP to cancel out like this:

```



```

Mica doesn't work anymore:
![Screenshot of black window](https://github.com/user-attachments/assets/b43dfbb5-464c-4023-9178-93e48d8d3a7a)

Note that sometimes, the screen only turns black after resizing the window.

### Steps to reproduce the bug
Repro project: [Mica repro.zip](https://github.com/user-attachments/files/17812056/Mica.repro.zip)
1. Create a project and add Win2D as dependency
2. Add the following XAML:
```xaml





```
3. Add the following C#
```c#
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}

CanvasSwapChain csc;

private void Swappy_SizeChanged(object sender, SizeChangedEventArgs e)
{
this.csc = new CanvasSwapChain(CanvasDevice.GetSharedDevice(), Math.Max((float)Swappy.ActualWidth, 1), Math.Max((float)Swappy.ActualHeight, 1), 96);
this.Swappy.SwapChain = this.csc;
DrawInPanel();
}

private void DrawInPanel()
{
using (var ds = this.csc.CreateDrawingSession(Microsoft.UI.Colors.Transparent))
{
ds.Clear(Microsoft.UI.Colors.Transparent);
ds.DrawText("Some text", 0, 0, Microsoft.UI.Colors.Red);
ds.DrawRectangle(0, 0, 100, 100, Microsoft.UI.Colors.Red);
}
this.csc.Present(0);
}
}
```
4. Observe Mica not working

### Expected behavior

Mica should work without having to set a margin somewhere.

### Screenshots

_No response_

### NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

### Windows version

_No response_

### Additional context

Windows version 24H2: 26100.2314

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the attached Mica repro with the MainWindow XAML and C# code on Windows 24H2 with Windows App SDK 1.6.3. Start at Swappy_SizeChanged, CanvasSwapChainPanel, and MicaBackdrop, comparing full-screen coverage with a one-pixel margin and resizing. Done means Mica remains visible without a margin and after resizing.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.