How to style a Button text in Grid, or a Label work as a Button.

WinterCloudWinterCloud GBMember ✭✭✭
edited July 2016 in Xamarin.Forms

I have a button added at the bottom row of the Grid. Space is an issue, so I only need a small button.

However, button by default is quite large, and with a lot of padding.

I tried changing HeightRequest to a smaller one, but the text of the button has not moved position, so only top of the text is showing.

Please advice how to style a button text and padding.

Or as label is quite easy to be style, can I make label works as a button like on a web page, ie label clicked event with a function, label don't have that event.

Thanks in advance.

Best Answers

Answers

  • WinterCloudWinterCloud GBMember ✭✭✭

    Thanks for the replies. @Ipdavies @AlessandroCaliaro

    Switched to use Label as Button now, works great just without pressing animation, which I'm ok with.

  • E75E75 NLMember ✭✭

    @Ipdavies, if i add 2 labels, then the page doesn't load.

        Label lbl = new Label { Text = "Test" };
            TapGestureRecognizer tap = new TapGestureRecognizer();
            tap.Tapped += (sender, e) =>
            {
                onPrevLabelClicked();
            };
    
    
            Label lbl1 = new Label { Text = "Test 1" };
            TapGestureRecognizer tap1 = new TapGestureRecognizer();
            tap1.Tapped += (sender, e) =>
            {
                onNextLabelClicked();
            };
        lbl1.GestureRecognizers.Add(tap);
           lbl.GestureRecognizers.Add(tap1);
    

    Maybe you can help?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @Eray said:
    @Ipdavies, if i add 2 labels, then the page doesn't load.

      Label lbl = new Label { Text = "Test" };
            TapGestureRecognizer tap = new TapGestureRecognizer();
            tap.Tapped += (sender, e) =>
            {
                onPrevLabelClicked();
            };
    
    
            Label lbl1 = new Label { Text = "Test 1" };
            TapGestureRecognizer tap1 = new TapGestureRecognizer();
            tap1.Tapped += (sender, e) =>
            {
                onNextLabelClicked();
            };
      lbl1.GestureRecognizers.Add(tap);
           lbl.GestureRecognizers.Add(tap1);
    

    Maybe you can help?

    That code is fine, That will not be the reason the page won't load. Maybe it's where your displaying the labels.

  • E75E75 NLMember ✭✭
    edited January 2017

    @ipdavies

    this is de code i'm using to display

     this.Content = new StackLayout
            {
                Children =
                {
                    lbl,
                    lbl1,
                    datePicker,
                    listView,
                }
            };
    
  • E75E75 NLMember ✭✭
    edited January 2017

    @ipdavies, this is the Code i'm using to display the labels

    this.Content = new StackLayout
            {
                Children =
                {
                    lbl,
                    lbl1,
                    datePicker,
                    listView,
                }
            };
    
  • seanydaseanyda GBMember ✭✭✭✭✭

    @Eray said:
    @ipdavies, this is the Code i'm using to display the labels

    this.Content = new StackLayout
    {
    Children =
    {
    lbl,
    lbl1,
    datePicker,
    listView,
    }
    };

    That also won't cause the page to break. Something else will be responsible... probably the list view

Sign In or Register to comment.