Entry name in code behind

BogdanUngureanuBogdanUngureanu USMember
edited November 2015 in Xamarin.Forms

Hello! Quick question : when creating an Entry in code behind, is there anyway to give it a name or and id in order to access it later? Example:

    Entry input = new Entry ();
    input.BackgroundColor = Color.Gray;
    input.Keyboard = Keyboard.Numeric;

Best Answer

Answers

  • ChaseFlorellChaseFlorell CAInsider, University mod

    it's called input in your case.

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    Make a variable for it on your class and then access it when you need it.

    public class RandomPage : ContentPage
    {
        private Entry input;
    
        public RandomPage()
        {
            input = new Entry ();
            input.BackgroundColor = Color.Gray;
            input.Keyboard = Keyboard.Numeric;
        }
    }
    
  • well that was obvious but if I am creating multiple inputs dynamically, it won't work like that.
    Example:

    for (int i = 0; i < numberOfColumns.Length; i++) {
                for (int j = 1; j < numberOfRows.Length - 1; j++) {
                    Entry input = new Entry ();
                    input.BackgroundColor = Color.Gray;
                    input.Keyboard = Keyboard.Numeric;
                    Grid.SetRow (input, j);
                    Grid.SetColumn (input, i);
                    grid.Children.Add (input);
                }
            }
    
  • thank you Adam, that was it!

Sign In or Register to comment.