Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Custom ButtonRenderer?

$
0
0

Hello forum,

I am trying to create a button with same layout as ImageCell (with image on the left) and two lines of text.
But I am stuck and dont know where to start. I did try creating custom button by using ButtonRenderer - but I am stuck at how can I add extra Text Fields to my renderer:
creating custom class menuButton

public class menuButton : Button
{
public static readonly BindableProperty FirstLineTextProperty =
BindableProperty.Create<menuButton, string>(p => p.FirstLineText, "");

    public string FirstLineText
    {
        get { return (string)base.GetValue(FirstLineTextProperty); }
        set { base.SetValue(FirstLineTextProperty, value); }
    }

    public static readonly BindableProperty SecondLineTextProperty =
        BindableProperty.Create<menuButton, string>(p => p.SecondLineText, "");

    public string SecondLineText
    {
        get { return (string)base.GetValue(SecondLineTextProperty); }
        set { base.SetValue(SecondLineTextProperty, value); }
    }
}

[assembly: ExportRenderer (typeof(menuButton), typeof(menuButtonRenderer))]

namespace DriverNavigationApp.iOS.CustomRenderer
{
public class menuButtonRenderer : ButtonRenderer
{

//At this part I simply don't know what to do to add two lines of text to button layout.

//this part working fine as allows to customize existing elements of the button
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);

        if (e.OldElement == null)
        {
            var nativeButton = (UIButton)Control;
            nativeButton.BackgroundColor = UIColor.Gray;
            // extra features to customize button appearence 
        }
    }
}

}

Will appreciate for any hint I can use.

Thank you


Viewing all articles
Browse latest Browse all 58056

Trending Articles