It is inside ListView> ItemTemplate> DataTemplate> ViewCe...">

How to get text from a post

I create a record using

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

It is inside ListView> ItemTemplate> DataTemplate> ViewCell

The fact is that I need a way, when the user presses the submit button, that ViewCell receives the text for writing in this cell. I use Binding to set values, so I don’t understand how to get the text.

+5
source share
2 answers

Seeing your code, I noticed why @sme's answer is not right for you. You are making a very confusing and poor use of bindings and xaml , and I'm sure switching to MVVM is the best you can do now.

But if you insist that the code is as it is now, you can simply add the response text tied to the Text Entry property, for example:

 <Entry Placeholder="Reply..." HorizontalOptions="FillAndExpand" Margin="0, 0, 0, 5" Text="{Binding Reply}"/> 

So, as you send the entire MessageObject to the tap command, you can get the text content exactly like this:

 public void ReplyCommandClick(string id, object msg) { MessageObject message = (MessageObject) msg; message.ShowReplyField = message.ShowReplyField ? false : true; //var viewcell = (MessageObject)((Label)msg).BindingContext; //viewcell. // There were no options for the entry var reply = msg.Reply; SendReply(id, msg, reply); } 
+2
source

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

Same:

 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 } 
+3
source

Source: https://habr.com/ru/post/1275676/


All Articles