简体   繁体   中英

binding a winforms control's property to multiple object properties

I am looking for a solution to bind a property of a windows forms control (Text of a button or a label) to multiple properties of one (or more) objects via a formatting string. Basically, the displayed text on a button should look like "static text $1 more static text $2" where $1 is bound to the to the property of an object and $2 is bound to a different property of the same or a different object. Is there an easy way to accomplish that?

You could encapsulate Property1 and Property2 in a third property that takes and returns the formatted string.

public string EncapsulatingProperty
{
    get { return "static text" + property1 + "more" + property2; }
    set { /* Parse the static text into the two variables */ }
}

要补充Eric的回答,“ 了解简单数据绑定”可以很好地阅读该主题。

如果您正在处理UX的WPF / Silverlight,我相信您可以编写一个ValueConverter来处理数据的正确显示...,在某些情况下,将值转换回去。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM