How to give unique id for each button

后端 未结 1 375
情深已故
情深已故 2020-12-22 08:06

I have buttons created by loop and each button it corresponds to a desk, so i have to able when i click a button i have to design spesific row of database

how i add

相关标签:
1条回答
  • 2020-12-22 08:45

    Create a custom button

    public class MyIDButton : Button
    {
        public static readonly BindableProperty ButtonIDProperty = BindableProperty.Create(nameof(ButtonId), typeof(int), typeof(MyIDButton), 999);
    
        public int ButtonId
        {
           get => (int)GetValue(ButtonIDProperty);
           set => SetValue(ButtonIDProperty, value);
        }
    }
    

    Then use it like

    var buttonteras = new MyIDButton 
            {
                Text = i.ToString(),
                HeightRequest = 45,
                WidthRequest = 45,
                Margin = 5,
                ButtonId = 1, //whatever your value
                BorderRadius = 100,
            };
    
    0 讨论(0)
提交回复
热议问题