Issue
I want to use the button to add entry text to the editor but I get an error! Here is my code:
public MainPage()
{
InitializeComponent();
var InputOrdersEntry = new Entry
{
FontSize = 10,
Placeholder = "Enter Your order",
PlaceholderColor = Color.Gray,
TextColor = Color.White,
BackgroundColor = Color.DarkGray,
MaxLength = 1000,
Keyboard = Keyboard.Text,
IsSpellCheckEnabled = false,
IsTextPredictionEnabled = false
};
Button EnterTextToEditorButton = new Button
{
FontSize = 10,
Text = "Enter",
};
var LogsEditor = new Editor
{
FontSize = 10,
TextColor = Color.White,
BackgroundColor = Color.DarkGray,
MaxLength = 100000,
IsSpellCheckEnabled = false,
IsTextPredictionEnabled = false,
IsReadOnly = true,
};
}
private void EnterTextToEditorButton (object sender, EventArgs e)
{
LogsEditor.Text += InputOrdersEntry.Text;
}
And this is Errors: Error CS0103 The name 'LogsEditor' does not exist in the current context Error CS0103 The name 'InputOrdersEntry' does not exist in the current context
What should I do to fix this errors and do my job too?
Solution
You should declare the LogsEditor/InputOrdersEntry
at the class level so that they can be accessed in whole class. If you declared them in one method, it can only be accessed in that method:
The complete code here:
public partial class MainPage : ContentPage
{
//declaring here as a class level variable
public Editor LogsEditor;
public Entry InputOrdersEntry;
public MainPage()
{
InitializeComponent();
InputOrdersEntry = new Entry
{
FontSize = 10,
Placeholder = "Enter Your order",
PlaceholderColor = Color.Gray,
TextColor = Color.White,
BackgroundColor = Color.DarkGray,
MaxLength = 1000,
Keyboard = Keyboard.Text,
IsSpellCheckEnabled = false,
IsTextPredictionEnabled = false
};
Button EnterTextToEditorButton = new Button
{
FontSize = 10,
Text = "Enter",
};
LogsEditor = new Editor
{
FontSize = 10,
TextColor = Color.White,
BackgroundColor = Color.DarkGray,
MaxLength = 100000,
IsSpellCheckEnabled = false,
IsTextPredictionEnabled = false,
IsReadOnly = true,
};
}
private void EnterTextToEditorButton(object sender, EventArgs e)
{
LogsEditor.Text += InputOrdersEntry.Text;
}
}
Answered By - nevermore
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.