Hello,
I might ask a pretty easy question but I have been trying to get the size of the Screen in a custom renderer to change the size of a Button accordingly. I might be doing something wrong, but then again, I am a bit lost since everytime I try to get the Width and the Height of a Context, I get -1.
Here is the code I am using for android renderer :
public class FBButtonRenderer : ButtonRenderer
{
int i;
Typeface myType;
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
var button = e.NewElement; // Xamarin.Forms.Button control
i = Width; <----------- My problem lies here
if (this.Control != null)
{
Drawable img = this.Context.Resources.GetDrawable(Resource.Drawable.facebooklogomini);
myType = Typeface.CreateFromAsset(this.Context.Assets, "Raleway-Thin.ttf");
Control.SetTypeface(myType, TypefaceStyle.Normal);
Control.SetBackgroundColor(Android.Graphics.Color.ParseColor("#3c5a99"));
Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(img, null, null, null);
}
}
}
I have been searching the web for an answer, but since I can't find one, maybe it is the wrong procedure. I have been vaguely thinking about using an interface to get the Width and Height of the screen but I am not sure if it is the right way.
Anyhow, I am leaving this question in your care. Thank you for your patronage.