Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetAlphaMask() visual empty for Path #9944

Closed
abrown313 opened this issue Sep 3, 2024 · 1 comment
Closed

GetAlphaMask() visual empty for Path #9944

abrown313 opened this issue Sep 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@abrown313
Copy link

Describe the bug

When calling Shape.GetAlphaMask on a Microsoft.UI.Xaml.Shapes.Path, no visual is returned.

Steps to reproduce the bug

XAML

<Canvas>
    <Rectangle x:Name="ShadowHost" Height="400" Width="400" Canvas.Left="0" Canvas.Top="0"/>
    <TextBlock x:Name="MyText" Foreground="Black" Canvas.Left="0" Canvas.Top="0">Testing</TextBlock>
    <Rectangle x:Name="MyRectangle" Fill="Black" Canvas.Left="0" Canvas.Top="0" Height="100" Width="200"/>
    <Path x:Name="MyOtherPath" Fill="Black" Canvas.Left="0" Canvas.Top="0">
        <Path.Data>
            <GeometryGroup>
                <RectangleGeometry Rect="0,0,200,100"/>
            </GeometryGroup>
        </Path.Data>
    </Path>
</Canvas>

CPP

auto hostVisual = winrt::Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::GetElementVisual(ShadowHost());
auto compositor = hostVisual.Compositor();

auto dropShadow = compositor.CreateDropShadow();
dropShadow.Color(winrt::Windows::UI::ColorHelper::FromArgb(255, 0, 0, 0));
dropShadow.BlurRadius(25);
dropShadow.Opacity(0.5);
auto pathMask = MyOtherPath().GetAlphaMask();
dropShadow.Mask(pathMask);

auto spriteVisual = compositor.CreateSpriteVisual();
spriteVisual.Size({ 400,400 });
spriteVisual.Shadow(dropShadow);

winrt::Microsoft::UI::Xaml::Hosting::ElementCompositionPreview::SetElementChildVisual(ShadowHost(), spriteVisual);

With auto pathMask = MyOtherPath().GetAlphaMask();, no shadow is created. I know the visual is empty because I also tried setting the GetAlphaMask output directly to the host visual which worked for the other shapes/text but not the Path.
image

Expected behavior

I'd expect the code above produce the same results as with the Rectangle shape directly. Then, I'd expect to also be able to generate masks/shadows for arbitrary geometry within the path (e.g. closed, filled path figures).

Screenshots

auto pathMask = MyRectangle().GetAlphaMask();
image

auto pathMask = MyText().GetAlphaMask();
image

NuGet package version

WinUI 3 - Windows App SDK 1.5.6: 1.5.240802000

Windows version

No response

Additional context

No response

@abrown313 abrown313 added the bug Something isn't working label Sep 3, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Sep 3, 2024
@abrown313
Copy link
Author

abrown313 commented Sep 6, 2024

Resolved by giving the Path explicit width & height. Did this precisely in code behind using the Path data's Geometry.Bounds.

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-triage Issue needs to be triaged by the area owners labels Sep 6, 2024
@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants