作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在为一款游戏开发自定义 UI 引擎。我有非常基本的 C# 技能(我是一名 C 程序员),但我在弄清楚如何将 UI 元素与其代表的数据链接起来时遇到了问题。这就是我的意思:
class SomeClass
{
//some stuff
//This is what I want to monitor and/or modify.
private SomeType _myVariable;
}
别处...
class UITextboxWidget
{
//methods and stuff
}
现在,我想要的是当用户在文本框中输入值更改时修改 _myVariable
元素,反之亦然。
我首先尝试通过在 MyClass
构造函数中调用一个方法并通过引用在 _myVariable
上传递一个属性来实现它,但我很快发现这在 C# 中是不可能的。
然后我查看了属性,发现您可以创建新属性:这就是我的想法。
class MyClass
{
[TextBoxAttribute(some, parameters)]
private SomeType _myVariable;
}
这将使嵌入到 UI 系统中变得非常容易,但我不太确定是否可以以这种方式使用属性。
所以,简单地说:
最佳答案
你想要做的是所谓的“数据绑定(bind)”。具体你的情况是Object Data Binding .点击此链接即可开始。
关于c# - 将 UI 对象链接在一起 : could I do it with attributes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6237326/
我是一名优秀的程序员,十分优秀!