开发者

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 */ }
}


To add on Eric's response, Understanding Simple Data Binding can provide a good read on the subject.


IF you are dealing with WPF/Silverlight for the UX, I believe you can write a ValueConverter to handle the proper displaying of the data... and in some instances, convert the values back.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜