Skip to content

create a DropShadow behind a control #10295

@tpoint75

Description

@tpoint75

Describe the bug

I cant create a DropShadow behind a control. The shadow is always in front of it!

void ApplyDropShadow(FrameworkElement const& element) {

        // Get the Compositor and Visual for the element
        auto visual = ElementCompositionPreview::GetElementVisual(element);
        auto compositor = visual.Compositor();

        // Create a DropShadow
        DropShadow dropShadow = compositor.CreateDropShadow();
        dropShadow.Color(winrt::Windows::UI::ColorHelper::FromArgb(255, 0, 255, 255)); 
        dropShadow.BlurRadius(30.0f);
        dropShadow.Opacity(0.8f);
        dropShadow.Offset({ -5.0f, -5.0f, 0.0f });

        // Create a SpriteVisual and set the shadow
        SpriteVisual shadowVisual = compositor.CreateSpriteVisual();
        shadowVisual.Shadow(dropShadow);

        // Set the size of the shadow to match the element
        shadowVisual.Size({ element.ActualSize().x + 10, element.ActualSize().y + 10 });

        // Place the container visual behind the XAML element
        ElementCompositionPreview::SetElementChildVisual(element, shadowVisual);
}

Steps to reproduce the bug

execute code

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Packaging type

No response

Windows version

No response

IDE

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssue needs to be triaged by the area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions