Bind a label to a “variable”

后端 未结 4 1060
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 05:02

Say I have a global variable INT named X. Since X is global, we can assume that anything can modify its value so it is being changed everytime.

Say I have a Label co

4条回答
  •  星月不相逢
    2020-12-05 05:28

    I don't think you'd be able to bind to a public variable. A variable by itself doesn't have the ability to notify listeners of a change in its value.

    That is why you need to wrap the variable in a property. In the setter you raise an event to notify the UI controls that are bound to it, so that they can refresh and display the new value. The framework has a mechanism for this - INotifyPropertyChanged - try this link for a how-to.

提交回复
热议问题