如何为数据列的每个单元格创建一个 diff 数据模板,以便它可以检查业务逻辑并提供 diff 数据模板
我的要求是:我必须比较数据网格的数据单元格中的值,并希望根据某些业务逻辑在其旁边显示一个箭头(向上绿色,向下红色,等于橙色)。
我是 silverlight MVVM 的新手。我可以用数据模板列来做吗?如果是这样,我怎样才能将每个单元格值与业务逻辑进行比较。
有人可以帮助我吗?这真的很有帮助。
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 business 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单元格的数据模板可以包含您想要显示的所有可能的控件(向上箭头、向下箭头、等于),并且您可以将每个控件的可见性绑定到某个属性,该属性可用于确定要显示的控件。
创建一个用于绑定的 ValueConverter,它将获取值(从绑定传递)以及 ConverterParameter。然后转换器可以返回适当的可见性。
这不是世界上最干净的解决方案,但它确实有效。
IMO,最干净的解决方案是使用某种 DataTemplateSelector 控件(请参阅 http://www .codeproject.com/KB/silverlight/SLTemplateSelector.aspx)
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)