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

First app and little problem

$
0
0

My app have 2 buttons, if I click + the label is increased by 1 whereas if I click - the label is decreased by 1.

Problem : the label number is increasing/decreasing only 1 time.
I just started Xamarin today, please consider I am a beginner. Thx

    public static Page GetMainPage ()
    {   
        var stackLayout = new StackLayout ();
        var number = 0;

        var numberLabel = new Label {
            Text = number.ToString(),
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand
        };

        var plusButton = new Button {
            Text = "+",
            BackgroundColor = Color.Aqua,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand
        };

        var lessButton = new Button {
            Text = "-",
            BackgroundColor = Color.Aqua,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            HorizontalOptions = LayoutOptions.CenterAndExpand
        }; 

        stackLayout.Children.Add (numberLabel);
        stackLayout.Children.Add (plusButton);
        stackLayout.Children.Add (lessButton);

        lessButton.Clicked += (object sender, EventArgs e) => {
            numberLabel.Text = (number - 1).ToString();
        };

        plusButton.Clicked += (object sender, EventArgs e) => {
            numberLabel.Text = (number + 1).ToString();
        };


        return new ContentPage {
            Content = stackLayout
        };
    }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>