开发者

How to have a diff Data Template for each cell of a data coloumn so that it can check on business logic and give diff data templates

开发者 https://www.devze.com 2023-03-27 03:15 出处:网络
My requirement is: I have to compare the value in a data cell of a data grid and wish to display an arrow beside it (up green, down red, equal orange) based on some 开发者_如何学Cbusiness logic.

My requirement is: I have to compare the value in a data cell of a data grid and wish to display an arrow beside it (up green, down red, equal orange) based on some 开发者_如何学Cbusiness logic.

I'm new to silverlight MVVM. Can I do it with data template column? If so, how can I have each cell value compared with the business logic.

Can anybody help me? That would be really helpful.


The data template for your cell could have all the possible controls that you would want to display (up arrow, down arrow, equals), and you could bind the Visibility of each control to some property that can be used to determine which one to display.

Create a ValueConverter to use on the binding which will get the value (passed from the binding) along with a ConverterParameter. Then the converter can return the appropriate visibility.

It's not the cleanest solution in the world, but it works.

IMO, the cleanest solution would be to use some sort of DataTemplateSelector control (see http://www.codeproject.com/KB/silverlight/SLTemplateSelector.aspx)

0

精彩评论

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

关注公众号