I'm currently working on a custom UI engine for a game. I've very basic C# skills (I'm a C programmer by trade) and I'm having problems figuring out how to link a UI element with the data it represents. Here's what I mean:
class SomeClass
{
//some stuff
//This is what I want to monitor and/or modify.
private SomeType _myVariable;
}
Elsewhere...
class UITextboxWidget
{
//methods and stuff
}
Now, what I want is for the _myVariable element to be modified when the users enters a value in the textbox changes, and vice versa.
I first tried doing it by calling a method in the MyClass constructor and passing a Property on _myVariable by reference but I quickly discovered that this is not possible in C#.
Then I had a look at attributes and discovered you can create new ones : this is what I had in mind.
class MyClass
{
[TextBoxAttribute(some, parameters)]
private SomeType _myVariable;
}
That would make the embedding in the UI system very easy, but I'm not quite sure if it is possible to use attributes in this manner.
So, simply put:
What you want to do is called 'Databinding'. Specificly in your situation, it is Object Data Binding. Follow this link and it will get you started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With