Effects in Xamarin Forms is a very awesome feature and in this blog post we will deep dive in Effects.
As per official documentation of Xamarin
However creating a custom renderer in order to perform a very simple control customization is really a heavy-weight response. Effects simplify this process, allowing the native controls on each platform to be more easily customized.
When we create Effect we have to crate a Effect class per platform , For example to implement a shadow effect our classes amy look like these.
Now the Million $ Question is
Why to write an Effect while same can be done by Custom Renderer ?
Each platform specific PlatformEffect class exposes the following properties:
Container – references the platform-specific control being used to implement the layout.
Control – references the platform-specific control being used to implement the Xamarin.Forms control.
Element – references the Xamarin.Forms control that’s being rendered.
Every Xamarin Forms Element have a collection that can hold all effects of that Element.
We are required to give a unique name to an effect so that we can resolve it. Once a effect is resolved we can add it in the Effects collection of a Xamarin Forms element but we can not use the same effect in another element again, we need to do that we need to resolve it again.
Effect eff = Effect.Resolve(“MyApp.ShadowEffect”));
OneButton.Effects.Add(eff); // ok
AnotherButton.Effects.Add(eff); // runtime error