我正在寻找一种解决方案,通过格式化字符串将 Windows 窗体控件的属性(按钮或标签的文本)绑定(bind)到一个(或多个)对象的多个属性。基本上,按钮上显示的文本应该类似于“静态文本 $1 更多静态文本 $2”,其中 $1 绑定(bind)到对象的属性,$2 绑定(bind)到相同或不同对象的不同属性。有没有一种简单的方法可以做到这一点?
最佳答案
您可以将 Property1 和 Property2 封装在第三个属性中,该属性接受并返回格式化的字符串。
public string EncapsulatingProperty
{
get { return "static text" + property1 + "more" + property2; }
set { /* Parse the static text into the two variables */ }
}
关于c# - 将 winforms 控件的属性绑定(bind)到多个对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2279056/