How to use the Text property of a TextField in a custom control computed property?

I created a custom control ‘statefulButton’ from Super ‘DesktopButton’.
This custom control has a computed property ‘CanConnect’ that stores a value in ‘mCanConnect’. So far so good.
Now, the getter should return True if the TextField ‘tf_host’ is empty, False if not. This text field in on the same window. However, this code produces the error message that the item does not exist. I am stuck. How do I get the text field’s text for processing in the getter? There’s something broken in my OOP thinking here.

You need to give your button access to the textfield or define some communication.

Code in your statefulButton class is not allowed to directly access anything outside of itself.

Potential solutions:
1.You pass tf_host.Text as a parameter. This would mean CanConnect can no longer be a computed property.
2. You allow statefulButton to ask for the data. This would be via a custom event defined in statefulButton that you would then implement on the window’s control instance.

I must admit i’m a little bit confused about what you are trying to achieve. Some things to think about…

  1. Why do you need a custom control?
  2. Why does a custom control need to use data from a window instance?
  3. What purpose does mCanConnect have?

Thanks @kevin_g. Your explanation #1 leads me on the right track.
I am obviously doing it the wrong way, but I could not nail it.
What I want to achieve:
On the window is a button that should only be active when certain conditions are met: 4 text fields on the layout not being empty. If one of these text fields is empty, the button should stay or flip back to inactive.
Coming from procedural languages, I need to change my way of thinking.

You can probably do this without a custom control.

1.Add a button to the window using the Library.
2.Add a method to the window (maybe named SetButtonState) that sets the button enabled value based on your logic.
3.Call the SetButtonState method in the Window’s Open event to set the initial state.
4.Add a LostFocus event to every relevant text field on the window and call the SetButtonState method.

NOTE. I’ve used the API v1 names here so they may be different if you are using API v2.

1 Like