C#, PHP, Xamarin, Mono tips

Monday, January 26, 2015

Easy click (tap) handler for controls in Xamarin.Forms

8:11 AM Posted by asmodeus , , , No comments

In Xamarin.Forms the views does not have default click event. In my project I wanted images that can be clickable, so I used gesture recognizers. This little helper class saved my time.
Thats all you need, now how to use it.

Object or Array to Dynamic in C#

7:49 AM Posted by asmodeus , , No comments

Put this code in your project folder and use it anywhere you want. It's based on Jorge Fioranelli's code.. http://blog.jorgef.net/2011/06/converting-any-object-to-dynamic.html

How to center an image in Xamarin.Forms XLabs ImageButton

6:46 AM Posted by asmodeus , , , No comments

In Xamarin.Forms the Button control does not have much control on image drawing on the Button itself. There comes the XLabs solution, but it still didn't feel right for me. I needed a button with an icon in the middle of it, and also didn't like the way it resized my image.
So I needed a custom control for it. Instead of writing a control I decided to fork and modify <XLabs.Forms controls.

Below is my modifications to XLabs ImageButton control.

In the XLabs.Core project I modified the Enums/ImageOrientation.cs
At the end of the Enum I appended the above code.

And then the real stuff..

Add the following code below

And then this method

And then the following code to the method SetImageSourceAsync

Almost finished, one last touch: change this line


to:

And remove the trailing close bracket }
In the code you use the ImageButton like the following..

There you go, much better