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

Unable to apply DropShadow to an Ellipse filled with RadialGradientBrush #3098

Closed
timunie opened this issue Jan 12, 2020 · 8 comments
Closed
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior WinUI 💠 Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3.

Comments

@timunie
Copy link

timunie commented Jan 12, 2020

Describe the bug

I am trying to apply a DropShadow to an Ellispe filled with a RadialGradientBrush I am not able to get this to work. The DropShadowPanel works as expected if I change the Brush to a SolidColorBrush

Steps to Reproduce

<controls:DropShadowPanel Canvas.Left="{Binding Left}"
                            Canvas.Top="{Binding Top}"
                            BlurRadius="20"
                            IsMasked="True"
                            OffsetX="10"
                            OffsetY="10"
                            ShadowOpacity="1"
                            Color="Black">
    <Ellipse Width="{Binding Diameter}"
                Height="{Binding Diameter}"
                Fill="{Binding Fill}">
        <Ellipse.RenderTransform>
            <TranslateTransform X="{Binding Left}" Y="{Binding Top}" />
        </Ellipse.RenderTransform>
    </Ellipse>
</controls:DropShadowPanel>

where Fill is a RadialGragientBrush generated in code behind

image
With RadialGadientBrush

image
With SolidColorBrush

Expected behavior

image 2 with the RadialGradientBrush applied

Screenshots

see above

Environment

NuGet Package(s): 

Package Version(s): 

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [X] May 2019 Update (18362)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [X] October 2018 Update (17763)
- [X] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X] Desktop
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ ] 2017 (version: )
- [X] 2019 (version: 16.4.2) 
- [ ] 2019 Preview (version: )

Additional context

Here is a sample App if it helps. Note: I am not a programmer by profession, so maybe this code is not up to your standard 😄 https://github.com/timunie/Bubblez

@timunie timunie added the bug 🐛 An unexpected issue that highlights incorrect behavior label Jan 12, 2020
@ghost ghost added the needs triage 🔍 label Jan 12, 2020
@Kyaa-dost Kyaa-dost added the WinUI 💠 Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3. label Jan 23, 2020
@michael-hawker
Copy link
Member

Thanks for the report @timunie, we definitely see this behavior. Probably has to do with how masks are being generated.

However, the brush is being added to WinUI now: microsoft/microsoft-ui-xaml#266

So we should validate the initial implementation of their brush and fix it there instead, as once that ships, we'll be deprecating the version in the toolkit.

FYI @jesbis @SavoySchuler

@jesbis
Copy link

jesbis commented Jan 24, 2020

Yeah masks look like the culprit - I think this may be a generic issue with calling GetAlphaMask() (like DropShadowPanel does when setting IsMasked=true) on any element filled with any XamlCompositionBrush (which is what both implementations of RadialGradientBrush use). Even using a solid color CompositionColorBrush doesn't work.

I opened a WinUI bug here for the generic issue:
microsoft/microsoft-ui-xaml#1884

Related: @michael-hawker are these docs out of date? I don't see the IsMasked property:
https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.ui.controls.dropshadowpanel?view=win-comm-toolkit-dotnet-stable

@timunie
Copy link
Author

timunie commented Jan 25, 2020

Thank you for taking your time and inspection. I didn't know that this was available in WinUi already. Should I close this issue?

Have a nice weekend
Tim

@michael-hawker
Copy link
Member

@timunie the first preview was just added, so I think we should leave this open until we've confirmed hand-off with WinUI if it's a general composition brush issue.

@michael-hawker
Copy link
Member

@jesbis yeah, I think the doc is out of date, we had issues trying to get them updated after the last release, I need to get back to investigate what happened.

Thanks for investigating and opening the WinUI issue.

@michael-hawker michael-hawker added this to the 6.1 milestone Jan 28, 2020
@codendone
Copy link

Shape.GetAlphaMask() is created by drawing the shape into a static bitmap. The actual XamlCompositionBrushBase.CompositionBrush can't be used for this, so it gets drawn with the FallbackColor. The default FallbackColor for XamlCompositionBrushBase is Transparent, so if the brush or the app doesn't set a different FallbackColor, the drawn shape in the AlphaMask will be completely transparent. Setting, for example, FallbackColor = Colors.Green in the sample app's construction of the RadialGradientBrush in Ball.cs gets the shadow to render.

(There is a separate issue somewhere where the shadows of balls which get added by clicking all end up in the upper-left corner. But there are shadows! 😄)

@timunie
Copy link
Author

timunie commented Feb 2, 2020

Hi @codendone
Thank you for looking into this. I can confirm that it now renders as expected. Maybe there should be an example with FallbackColor in the Demo-App for others with a similar issue.

Happy Sunday
Tim

@michael-hawker michael-hawker removed this from the 6.1 milestone May 26, 2020
@michael-hawker
Copy link
Member

Going to close this as there's a general issue open on the platform and a workaround by setting the FallbackColor.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior WinUI 💠 Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3.
Projects
None yet
Development

No branches or pull requests

5 participants