0
votes

I am unable to grab the value of a binding value in a label in Xamarin forms view. I want to me able to manipulate the label text then display it back to the view. Currently an API is providing the initial value of the EventCode variable and displaying it directly to the view. I want modify the EventCode variable value before its displayed to the view.

View:

 Label x:Name="myLabel" Text={"Binding EventCode}"

C# behind code:

string x = Label.mylabel.text; 

/////// Class:

public class EventSummary {

public string EventCode {get; set}

}

1
if you are using binding, you shouldn't interact directly with the Label, you should interact with the property the label is bound to. That's the purpose of binding - to provide separation between your UI and the data.Jason
Can you show an example?DevtoDev
Your Label is bound to the value of EventCode. Any changes to EventCode should be reflected in your UI. However, in order for this to work the class assigned to your BindingContext must implement INotifyPropertyChanged.Jason
@DevtoDev As Jason indicated you accesing the property binded to the Label should help you do what you want. Show more of your code behind and explain why you need that value for so we can guide you.pinedax
Currently an API is providing the initial value of the EventCode variable and displaying it directly to the view. I want modify the EventCode variable value before its displayed to the view.DevtoDev

1 Answers

2
votes

mylabel.SetBinding(Label.TextProperty, new Binding("EventCode"));

You can store the mylabel text into string by following way.

string str = mylabel.GetValue(Label.TextProperty).ToString();