Delpin Susai Raj Monday, 3 February 2020

Xamarin.Forms - Use BindableProperty in Effects

In this blog, you will learn how to use BindableProperty Effects in Xamarin.Forms


Tint Color Sample -  https://xamarinmonkeys.blogspot.com/2020/02/xamarinforms-tint-image-using-effects.html

(The Blog about change Image color at Runtime using Tint Color)


Introduction

Xamarin.Forms code runs on multiple platforms - each of which has its own filesystem. This means that reading and writing files are most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.

Tint Image

TintImage is used for change image color at runtime with the help of effects, you can achieve with custom render also. Tint images mainly used to reduce the usage of the images.

BindableProperty

Attached properties can be used to define effect parameters that respond to runtime property changes. This article demonstrates using attached properties to pass parameters to an effect and changing a parameter at runtime.

Prerequisites
  • Visual Studio 2017 or later (Windows or Mac)
The Problem

We are not able to create a BindableProperty in Effect.

Solution

Create Effect

Now, Create a TintImage class inherit from RoutingEffect for Change image color.

TintImage.cs

Create Static Class

Here, I'm Going to create a Static Class for creating BindableProperty to my Effect.

TintImageEffect.cs

Android Implementation

Here, Implement Platform Effects for TintImage at Runtime.

TintImageImpl.cs

iOS Implementation

Here, Implement Platform Effects for TintImage at Runtime.

TintImageImpl.cs

Create ViewModel

Now, Create a Property for Binding the TintColor to View. and Create ChangeColorCommand For Change image color at runtime.

MainPageViewModel.cs

Consuming the TintImage

Now, Use the TintImage Effect in your XAML code.

MainPage.xaml

Click the "Play" button to try it out.

Wow, It's Working.😍

I hope you have understood how to use BindableProperty Effects in Xamarin.Forms.

Thanks for reading. Please share your comments and feedback. Happy Coding 🙌

1 comment:

  1. Look at the way my friend Wesley Virgin's autobiography launches with this SHOCKING and controversial VIDEO.

    Wesley was in the military-and soon after leaving-he unveiled hidden, "mind control" secrets that the government and others used to get whatever they want.

    THESE are the exact same SECRETS tons of celebrities (especially those who "come out of nothing") and elite business people used to become wealthy and successful.

    You probably know how you only use 10% of your brain.

    That's really because most of your brain's power is UNTAPPED.

    Maybe this thought has even occurred INSIDE OF YOUR very own head... as it did in my good friend Wesley Virgin's head around 7 years ago, while riding a non-registered, trash bucket of a car with a suspended driver's license and with $3.20 on his bank card.

    "I'm very fed up with going through life check to check! When will I finally make it?"

    You took part in those types of conversations, isn't it so?

    Your success story is going to start. You just have to take a leap of faith in YOURSELF.

    Watch Wesley Virgin's Video Now!

    ReplyDelete