microsoft / microsoft/microsoft-ui-xaml
Mica get's overdrawn by Swapchain when Swapchain covers entire screen
Nobody has claimed this yet.
- 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:

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:

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:

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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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