question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting Label text using Text doesn't work

See original GitHub issue

When creating a label like var label = new Label { Text = "test", X = 1, Y = 1 } the label text is not visible. Creating it like var label = new Label("test") { X = 1, Y = 1 } works.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
BDispcommented, Jun 21, 2021

// result in exactly the same code and constructors being called new MyClass(){SomeVar =1}; new MyClass{SomeVar =1};

I did a little change to prove the above.

[Theory]
[InlineData (1)]
[InlineData (2)]
[InlineData (3)]
public void LabelChangeText_RendersCorrectly_Constructors (int choice)
{
	var driver = new FakeDriver ();
	Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true)));

	try {
		// Create a label with a short text 
		Label lbl;
		var text = "test";

		if (choice == 1) {
			// An object initializer should call the default constructor.
			lbl = new Label { Text = text };
		} else if (choice == 2) {
			// Calling the default constructor followed by the object initializer.
			lbl = new Label () { Text = text };
		} else {
			// Calling the Text constructor.
			lbl = new Label (text);
		}
		lbl.ColorScheme = new ColorScheme ();
		lbl.Redraw (lbl.Bounds);

		// should have the initial text
		Assert.Equal ('t', driver.Contents [0, 0, 0]);
		Assert.Equal ('e', driver.Contents [0, 1, 0]);
		Assert.Equal ('s', driver.Contents [0, 2, 0]);
		Assert.Equal ('t', driver.Contents [0, 3, 0]);
		Assert.Equal (' ', driver.Contents [0, 4, 0]);
	} finally {
		Application.Shutdown ();
	}
}

1reaction
BDispcommented, Jun 21, 2021

I confirm @tznind .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to change label text using JavaScript - html
The label is undefined in your case because your code is being called before the actual label exists on the page.
Read more >
Set label's text not working for me!
Today, when I was working on my submission for WDC 13, I realized that the label's text wasn't getting changed at all. In...
Read more >
Question - Label text does not change when text parameter ...
Question - Label text does not change when text parameter is modified by a script - Unity Forum.
Read more >
Problem changing a label's text : r/godot
Problem changing a label's text. Hello, I started using Godot a few days ago and for my project I am trying to do...
Read more >
Label - .NET MAUI
NET MAUI) Label displays single-line and multi-line text. Text displayed by a Label can be colored, spaced, and can have text decorations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found