WPF DataGrid相对于数据交替显示行颜色 [英] WPF DataGrid alternating rows color relatively to data

查看:266
本文介绍了WPF DataGrid相对于数据交替显示行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我希望这是一个简单的方法,但是我对WPF还是很陌生,所以我还没有找到答案.

问题出在这里:我得到了一个简单的WPF Datagrid(.Net 4.0),用于存储按日期排序的报告.我希望同一天的数据网格中的所有条目都使用一种颜色,并在另一天与另一种颜色交替使用.
举例来说,所有成对的天数线必须为红色,而另一对为绿色.

Hi everybody !
I hoped this one was a simple one, but I''m quite new to WPF, so I didn''t found an answer yet.

Here is the problem :I got a simple WPF Datagrid (.Net 4.0) storing reports, sorted by date. I want all the entries in the datagrid of the same day to be in one color, and alternate with another one for the other day.
Let''s say for exemple, that all pair days number lines have to be red, and the other green.
The

AlternatingRowBackground

属性仅交替显示每一行,在这种情况下,我看不到如何使用

property only alternates every line, and I don''t see how I could use

AlternatingCount

...
而且,我实际上在网格中有一个日期"列.

我认为这与模板或触发器有关,对吗?

预先感谢您的帮助!

in this context...
And, i actually got a "Date" column in the Grid.

I think it has something to do with templates or triggers, am I right ?

Thanks in advance for your help !

推荐答案

有些事情在后面的代码中容易完成.您可以在数据网格上设置LoadingRow事件.然后,在事件中,根据所需条件设置行背景.

祝你好运
Some things are much easier done in code behind. You can set up a LoadingRow event on your data grid. Then, in the event, set the row background based on whatever criteria you want.

Good Luck


这篇关于WPF DataGrid相对于数据交替显示行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆