绑定和吸气剂 &二传手 [英] Binding and Getters & Setters
本文介绍了绑定和吸气剂 &二传手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么public string name {get;set;}
绑定时有效,但 public string name;
不行?为什么当它们都返回相同的字符串时需要 getter?
Why does public string name {get; set;}
work when binding, but public string name;
does not? Why is the getter required when they both return the same string?
推荐答案
因为您只能绑定到 WPF 中的公共属性.以下是字段而不是属性:
Because you can only bind to public properties in WPF. The following is a field and not a property:
public string name;
绑定引擎仅在运行时使用反射计算绑定表达式时才查找属性.
The binding engine only looks for properties when the binding expressions are evaluated using reflection at runtime.
这篇关于绑定和吸气剂 &二传手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文