Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get text from entry

I create an entry using

 <Entry Placeholder="Reply..."/>

It is inside a ListView > ItemTemplate > DataTemplate > ViewCell

The thing is I need a way once a user clicks the submit button in that ViewCell it gets the text for the entry in that cell. I am using Binding to set the values so I don't how to get the text.

like image 936
Dan Avatar asked Mar 03 '18 06:03

Dan


1 Answers

When you handle the button's click event, assuming you are using an event handler to listen to the Clicked event, you can get the BindingContext of the button (which should also be the same BindingContext for the entire ViewCell).

Like so:

public void OnButtonClicked(object sender, EventArgs e)
{
    // Assuming the List bound to the ListView contains "MyObject" objects,
    // for example List<MyObject>:

    var myObjectBoundToViewCell = (MyObject)((Button)sender).BindingContext;

    // and now use myObjectBoundToViewCell to get the text that is bound from the Entry
}
like image 140
sme Avatar answered Oct 26 '22 09:10

sme