-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
Currently, while all VisualElement
objects in .NET MAUI support the Shadow
property with attributes such as Offset
(x, y), Opacity
, Brush
(color), and Radius
, there is no native support for defining shadows directly through CSS. This feature request proposes the addition of CSS syntax (either through the CSS equivalent box-shadow
or a custom MAUI format) and corresponding support for styling shadows in .NET MAUI.
Public API Changes
I would expect the following API changes to be required, please do add to this list as I'm sure it's not entirely complete.
- Add
StyleProperty
declarations toAssemblyInfo.cs
(also unsure whether thePropertyOwnerType
setup is correct here).
[assembly: StyleProperty("shadow", typeof(VisualElement), nameof(VisualElement.ShadowProperty))]
[assembly: StyleProperty("shadow-color", typeof(VisualElement), nameof(Shadow.BrushProperty), PropertyOwnerType = typeof(Shadow))]
[assembly: StyleProperty("shadow-offset", typeof(VisualElement), nameof(Shadow.OffsetProperty), PropertyOwnerType = typeof(Shadow))]
[assembly: StyleProperty("shadow-radius", typeof(VisualElement), nameof(Shadow.RadiusProperty), PropertyOwnerType = typeof(Shadow))]
[assembly: StyleProperty("shadow-opacity", typeof(VisualElement), nameof(Shadow.OpacityProperty), PropertyOwnerType = typeof(Shadow))]
- Add
TypeConverter
to allow conversion from a string to a completely definedShadow
. - The necessary plumbing to combine the CSS with actually setting the properties and assigning a Shadow object.
- Support for setting only some of the
Shadow
properties and combining them through multiple CSS classes.
To support setting individual properties we will probably need to come up with a mechanism that can also initialize a Shadow object, given that all the other CSS-related styling is mapping properties whereas this is setting properties of a property. Perhaps something like an attached property setup that could set Shadow.Offset
etc?
Intended Use-Case
Using CSS to style the shadows, we could either use it to set a complete shadow in a single line, or use various classes and combine them accordingly through StyleClass
to make a shadow. Given that Shadow
translates so nicely to CSS, I feel like it's a missing piece that can go a long way to users styling their apps in a modern fashion.
/* Scenario 1: */
.shadow-singleline {
shadow: 4 4 8 #000000 0.5; /* OffsetX, OffsetY, Radius, Color, Opacity */
}
/* Scenario 2: */
.shadow-md {
shadow-offset: 4 4;
shadow-opacity: 0.5;
shadow-radius: 8;
}
.shadow-black {
shadow-color: #000000;
}
Which would be used as such in XAML:
<Label Text="Single Line Shadow" StyleClass="shadow-singleline" />
<Label Text="Combined Shadow" StyleClass="shadow-md,shadow-black" />