【发布时间】:2012-09-19 10:27:28
【问题描述】:
我有课
public class Car
{
[Description("name of the car")]
public string Name { get; set; }
[Description("age of the car")]
public int Age { get; set; }
}
是否有可能将描述属性绑定到标签内容。我正在寻找的解决方案不需要实例化 Car 对象。
【问题讨论】:
-
您不应该这样做,这是一种丑陋的填充 UI 元素的方式。您到底想实现什么 - 根据绑定的内容自动填充一个窗口?
-
是的,我想让 Windows 中的所有标签都从类属性属性“描述”中获取它们的内容。此属性也用于验证目的。
-
您应该将标签绑定到字符串资源文件中的文本。如果您的绑定项目可以更改,请使用 DataTemplates。
标签: c# wpf xaml data-binding