How can I add faded text to an empty TextField in UIToolkit?

In the attached image, you can see many text fields for some imaginary web service, each field is either filled or has placeholder text in it. That’s what I want. I want placeholder text. I understand that it exists by default in text-fields in unity, and if I want to modify what it is specifically I can open the UXML file and modify it there. The problem is that I’m building my UI through C#. That’s just how I prefer it. However, I can’t find a placeholder-text variable on the TextField in my C#, and by default it’s empty. This results in my just staring at an empty white box. I’ve discovered how I can manually set the text in the text-field, but I am unable to set the placement text on both the TextField or the TextElement within it.

I understand it may sound silly that I’m asking how to do a thing when I already acknowledged that I found a way to do it (building the UXML file and modifying it manually) but I strongly prefer building my UI at runtime through C#, that way it’s more dynamic. I also don’t need to find my elements this way because I store them as I create them. If there is a solution to this in C#, I would love to hear it. If not, I would greatly appreciate the parameter on the TextField being made publicly accessible for read/write in C#.

Edit to show what I was expecting it to be:

inputText.Q<TextElement>().placeholder = "Type Responses Here";

but like I said, the placeholder is not publicly accessible for some reason that I do not understand.

An example is right there in the docs: Unity - Manual: UXML element TextField

2 Likes