Jonathan Simon
Jonathan Simon

Reputation: 47

Xamarin Forms: I can't get the text from Xamarin.Forms.Editor

this is probably something really easy and i feel really stupid for having to ask for help with this but i can seem to get access to a Editors text from the CodeBehind file. I have tried numerous things and nothing worked, and i am about to blow up me computer because it drives me absolutely mad!

Please help me, i have no idea why this doesn't work because i have seen it exactly like this in other people's projects and it worked for them.

I am creating an Editor in my Page.xaml like this:

<Editor x:Name="desc" Placeholder="Describe your Problem"
HorizontalOptions="FillAndExpand" />

And i want to put the text from this Editor into a string variable in my Page.xaml.cs:

public string description = desc.Text;

But this doesn't work and i get the exception:

a field initializer cannot reference the non-static field or the static 
method or property Page.desc

Here is a screenshot of the two files:

Code

Upvotes: 0

Views: 928

Answers (1)

KiShOrE
KiShOrE

Reputation: 925

@Jonathan Simon Read Xamarin.Forms

Editor is a control where "x:Name" is the property to set the Control unique Id/Name to access that specific control from the code behind and for other use. "x:Text" is the property where you can get/set the text for that control. These two properties are provided for the different context.

And more over, I think you are newbie to the c#, please go through here

You should write the code in method or constructor based on your requirement. But variables can write any where. Please check variables and members of c#.

Upvotes: 2

Related Questions