As IdoT says, if you define an object at runtime, you need to keep a reference to it in order to access it, since it is impossible to give a name. I use a dictionary like this:
Dictionary<Guid, String> ControlsDictionary = new Dictionary<Guid, string>();
Then when I create the object:
Button bt = new Button {Text="Yay!"}; bt.Clicked += OnButtonClicked; StackLayout.Children.Add(bt); ControlsDictionary.Add(bt.Id, "myname");
In the Click event handler, I can determine the "name" of the sender:
async void OnButtonClicked(object sender, EventArgs args) { Button btn = (Button)sender; String NameofButton = ControlsDictionary[btn.Id]; }
You can also get Id from the "name":
Guid IdfromName = ControlsDictionary.First(x => x.Value == "Name").Key;
source share