Skip to content

[Spec] Shadows #9

Closed
Closed

Description

@jsuarezruiz

Shadows

Shadows create visual cues in the interface, which helps the human brain differentiate the UI element that the user sees. And, this the reason why actually mobile designers favor incorporating shadows in their designs.

shadows

API

The DropShadow class provides means of creating a configurable shadow that can be applied to a Layout.

Properties

  • Radius: The radius of the Gaussian blur used to generate the shadow.
  • Color: The color of the shadow.
  • Offset: Offset of the shadow relative to its Layout.
  • Opacity: The opacity of the shadow.
public class DropShadow : BindableObject
{
    public static readonly BindableProperty RadiusProperty = BindableProperty.Create(
        nameof(Radius), typeof(double), typeof(DropShadow), 10.0d);

    public double Radius
    {
        get => (double)GetValue(RadiusProperty);
        set => SetValue(RadiusProperty, value);
    }

    public static readonly BindableProperty ColorProperty = BindableProperty.Create(
        nameof(Color), typeof(Color), typeof(DropShadow), Color.Black);

    public Color Color
    {
        get => (Color)GetValue(ColorProperty);
        set => SetValue(ColorProperty, value);
    }    
    
    public static readonly BindableProperty OffsetProperty = BindableProperty.Create(
        nameof(Offset), typeof(Point), typeof(DropShadow), new Point(1, 1));

    public Point Offset
    {
        get => (Point)GetValue(OffsetProperty);
        set => SetValue(OffsetProperty, value);
    }
      
    public static readonly BindableProperty OpacityProperty = BindableProperty.Create(
        nameof(Opacity), typeof(double), typeof(DropShadow), 1.0d);

    public double Opacity
    {
        get => (double)GetValue(OpacityProperty);
        set => SetValue(OpacityProperty, value);
    }
}

Scenarios

Let's see an example using C #, XAML and CSS.

C# Example

var layout = new Grid();

var shadow = new DropShadow ();
shadow.Radius = 12;
shadow.Color = Color.Red;
shadow.Offset = new Point (12, 18);
shadow.Opacity = 0.75d;

layout.Shadow = shadow;

XAML Example

<Grid>
     <Grid.Shadow>
          <DropShadow
               Radius="12"
               Color="Red"
               Offset="12, 18"
               Opacity="0.75" />
     </Grid.Shadow>
</Grid>

CSS Example

box-shadow: 12px 18px 12px 12px red;

Backward Compatibility

We already have shadows in some of the Xamarin.Forms Layouts. Frame's HasShadow property would become deprecated (it could still be used, although the use of the Shadow property would be recommended).

Scope

In this Spec, we add shadows to the different Xamarin.Forms Layouts. Specific controls, such as a Label, do not fall within the scope (they could come later).

Difficulty : Medium

Activity

  1. samhouts commented on May 20, 2020

    @samhouts
    Contributor

    Looks great!

  2. vhugogarcia commented on May 22, 2020

    @vhugogarcia
    Contributor

    Awesome! I really would like to see this feature. However, I think we can take the opportunity to improve this a little more by adding gradient shadow capabilities.

    image

    As @jsuarezruiz mentioned it here: #11

    My recommendation is to enhance the "Color" property to use the new "Brushes" for gradients and solid colors.

    Sample

    <Grid>
         <Grid.Shadow>
              <DropShadow
                   Radius="12"
                   Offset="12, 18"
                   Opacity="0.75">
                   <DropShadow.Color>
                     <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
    	            <GradientStop Color="Yellow" Offset="0.0" />
    	            <GradientStop Color="Red" Offset="0.25" />
    	            <GradientStop Color="Blue" Offset="0.75" />
    	            <GradientStop Color="LimeGreen" Offset="1.0" />
    	         </LinearGradientBrush>
                   </DropShadow.Color>
              </DropShadow>
         </Grid.Shadow>
    </Grid>
    

    What do you think?

  3. Phenek commented on Jul 17, 2020

    @Phenek

    Could be great to add multiple Shadow for neuromorphic design.
    This is the new fashion things...

  4. themronion commented on Mar 1, 2021

    @themronion

    What about the color and offset of shadows on android (it is a well known limitation)? If shadows will be implemented as in Sharpnado.Shadows then i'm looking forward to this feature, otherwise - it is quite useless

  5. added this to the 6.0.100-preview.7 milestone on Jul 16, 2021
  6. Askar938 commented on Sep 7, 2021

    @Askar938

    I am very surprised that a basic feature as shadows for layouts and controls hasn't been a part of Xamarin.Forms, but I am glad it's going to be added to .NET MAUI.

  7. jsuarezruiz commented on Oct 22, 2021

    @jsuarezruiz
    ContributorAuthor

    Already implemented in Preview 9.

  8. ghost locked as resolved and limited conversation to collaborators on Feb 19, 2022
  9. added a commit that references this issue on Apr 15, 2026
    48feb96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal/opent/enhancement ☀️

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions