I have 开发者_C百科few labels I use for displaying results.
Basically, they display numbers in following format
string.Format("{0:0.#}", number)
Their Text
property is binded to objects. Result should be plus or minus signed.
Is there a way to set Foreground
property of label according to result sign? For example green plus results and red minus results?
A solution could be to add a ValueConverter that transforms the value to a brush. Bind the value to the Foreground property using the converter.
Here is an example
EDIT Another option would be to add an extra property to the object you are binding to. The property would be a Brush that changes with the number to the correct color. Then just bind the Foreground to the property. This approach is common in MVVM.
精彩评论