1

Adding Shadows with .NET MAUI

 2 years ago
source link: https://askxammy.com/adding-shadows-with-net-maui/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
.Net MAUI

Adding Shadows with .NET MAUI

Leomaris Reyes / 16 December, 2021

Howdy! 🙋‍♀️ Continuing with initiative, today is #DayEight and we will be learning about Shadows in .NET MAUI!

Adding shadows in our applications makes our design look more elegant and takes depth points in specific controls, in Xamarin Form we can do it using some resources such as a Custom Renderer. In this case, with .NET MAUI we already have the shadows integrated natively and consuming fewer resources to achieve this goal! For this reason, in this post, we will be learning a very simple way to do it! Let’s see!


Let’s start!

Knowing about Shadows

Preview 9, of .NET Maui, has given us Microsoft.Maui.Graphics library which provides us with a consistent UI drawing API based on native graphics engines, thus making it easier for us to add borders, shadows, between other super useful and wonderful functionalities that previously require greater use of resources. In this post, we will be focusing on the Shadows.

Some important points to highlight

  • Shadows can also be added in styles and in this way add them to all the components you need, this also allows us to give depth to the controls, have better performance and save code at the same time! 💚

  • Shadow is a BindableProperty this means that we can update the properties with bindings. 😎

And how can I implement it? 🧐

In the following image, I show you the simple structure of how we can do it!

La imagen tiene un atributo ALT vacío; su nombre de archivo es Shadows_MAUI-1024x570.png


Let’ see an example!

La imagen tiene un atributo ALT vacío; su nombre de archivo es Captura.png

<Image Source="askxammy.png" HeightRequest="210" WidthRequest="300"> <Image.Shadow> <Shadow Brush="Red" Offset="10,10" Radius="20" Opacity="0.9"/> </Image.Shadow> </Image>

Let’s know the properties:

To do it, you can add some of the following properties:

🟠 Brush:      It’s the color that the shadow will take.

🟠 Opacity:  It’s the opacity that the shadow will take.

🟠 Radius:    It’s the Gaussian blur’s radius used to generate the shadow.

🟠 Offset:     It is the Offset of the shadow in relation to the visual element it contains.


And Done, in this simple way, we already have shadows to build a beautiful UI in .NET MAUI! 🤓

Spanish post:

References:

I hope this article has been super useful for you! ⭐️ Thanks for reading! 💚💕

Tagged .NetMaui, MAUI

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK