Buscar este blog

Xamarin.Forms: Get native image from ImageSource

Sometimes we need to implement images in our custom renderers and as a first solution most of developers take the decision to use a string property but for me is not the better and standard way to manage image resources on Xamarin.Forms, in this blog we will take a look to a helper class that help us to manage images resource on your Xamairn.Forms renderers using a IImageSourceHandler.

The first that we need is to check what kind of source have your ImageSource property using the next code

after this, with the returned IImageSourceHandler you can call the LoadImageAsync and passing the source that you want to be native and this method will be return for you an UIImage for iOS or a Bitmap for Android

Real World Example: "HeartBeatView" Control

Now we will create an example control using the previous code, we have 4 key file

Xamarin.Forms: Custom Context Actions on iOS
Hello folks now is time to talk about customize context action views on Xamarin.Forms cell for iOS (yes the red/light-gray options that appear when you swipe a cell) the default colors are not a good-looking, so right now is a little bit tricky to achieve that but we will use a reflection technique to achieve the next two escenarios: Change background color for default and destructive context actionSet custom view for default and destructive context action
first at all, lets take a look to native impl. on Xamarin.Forms Github project on the next url https://github.com/xamarin/Xamarin.Forms/blob/ae92582d5acad2b8aeab9a2ed5b490561e71bd6c/Xamarin.Forms.Platform.iOS/ContextActionCell.cs#L14

Here we have two key items "DestructiveBackground" and "NormalBackground" both are the Images that Xamarin.Forms use to put as background on the default ContextActions view(Gray/Red)