-
Notifications
You must be signed in to change notification settings - Fork 785
Open
Labels
area-MaterialsReveal, Acrylic, lighting, etc.Reveal, Acrylic, lighting, etc.bugSomething isn't workingSomething isn't workingteam-RenderingIssue for the Rendering teamIssue for the Rendering team
Description
Describe the bug
Consider the following scenario where we create a CanvasSwapchainPanel from Win2D while the Window has Mica as backdrop:
<Window
x:Class="App3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:xaml="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d">
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<xaml:CanvasSwapChainPanel x:Name="Swappy"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
SizeChanged="Swappy_SizeChanged"/>
</Grid>
</Window>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:
[...]
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,1">
[...]To add to the unusualness, when one sets the margin and padding of the Grid and CSCP to cancel out like this:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0,0,0,-1">
<xaml:CanvasSwapChainPanel x:Name="Swappy"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0,0,0,1"
SizeChanged="Swappy_SizeChanged"/>
</Grid>
Note that sometimes, the screen only turns black after resizing the window.
Steps to reproduce the bug
Repro project: Mica repro.zip
- Create a project and add Win2D as dependency
- Add the following XAML:
<Window
x:Class="App3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:xaml="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d">
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<xaml:CanvasSwapChainPanel x:Name="Swappy"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
SizeChanged="Swappy_SizeChanged"/>
</Grid>
</Window>- Add the following 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);
}
}- 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
Metadata
Metadata
Assignees
Labels
area-MaterialsReveal, Acrylic, lighting, etc.Reveal, Acrylic, lighting, etc.bugSomething isn't workingSomething isn't workingteam-RenderingIssue for the Rendering teamIssue for the Rendering team

