Use of `new` on Text property of Button
See original GitHub issueDescribe the bug
Button has new
on its Text property. This means that if you maintain a reference to it as a View
(e.g. keeping a list of views in your class) and assign its .Text
property then it is not properly preserved for use later on if you reference it as its explicit Type again.
This could be problematic in quite a few situations especially if using reflection. Is it possible to make Button
work without the new
keyword or make the Text property virtual and use override
instead of new
in Button if inheritence is the only way to make it work?
[Fact]
public void TestAssignTextToButton ()
{
View b = new Button ();
b.Text = "heya";
Assert.Equal ("heya", b.Text);
// fails here
Assert.Equal ("heya", ((Button)b).Text);
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top Results From Across the Web
Button.Text Property (System.Web.UI.WebControls)
Use the Text property to specify or determine the caption to display in the Button control. The value of this property, when set,...
Read more >Creating a buttons within buttons with more than one text ...
What I want to do is add an extra Text property and some buttons in my default button and when the button is...
Read more >The Button element - HTML: HyperText Markup Language
The <button> HTML element is an interactive element activated by a user with a mouse, keyboard, finger, voice command, or other assistive ...
Read more >Changing Button's Text - JavaScript
It checks if the button can be changed with the childNodes property first. If not, then it will try again using the value...
Read more >Providing button labels that describe the purpose of a button
The objective of this technique is to describe the purpose of a button by providing descriptive text as the button's accessible name. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That looks great! I think I got a bit lost in the text formatter and where everything was stored. But that looks like it ticks all the boxes 👍
Hmnnn I looked into it in https://github.com/tznind/gui.cs/tree/button-new-text but looks like a lot of work. The
Text
property on View has the textFormatter and its own layout logic. I didn’t want to make a lot of changes for something so small like this.In my branch I changed
Button.Text
it to useoverride
and function as it does now (callbase.Text
) but this means that Text always returns the formatted name (which is nice and consistent at least). But thats a breaking change and could be bad if people have code likeif(btn.Text == "Ok")
so I think we just have to live with the replication for now as its less disruptive.But to make crystal clear what the current situation is. The following test passes:
I’m going to leave this for now and just put a workaround in my code 😃