在运行期间将颜色背景更改为WPF中datagrid中的列 [英] Change color background a column in datagrid in WPF during running
问题描述
亲爱的每个人,
我有一个问题,我试图修复但我不能。 :(你能帮帮我吗?谢谢。
我的项目用的是WPF。我的问题如下:
我有一个datagrid,它有一个DataGridTextColumn改变颜色一个列根据status.I可以显示它。但这个问题是当我改变状态,刷新datagrid。它没有改变这一列的颜色。
我不知道如何表达你的理解。:( castoffs,我想在运行项目期间更改datagrid中列的颜色。
你能帮我一个解决方案吗?非常感谢你。
我尝试过:
我添加了数据:
Dear Everybody,
I have a problem, which i tried to fixed but i couldnt. :( Can you help me? Thank you.
My project is used WPF. And my problem as follows:
I have a datagrid, which has a DataGridTextColumn changes color of a column according to status.I can display it. But this problem is when i changed status, refreshed datagrid. It didnt change color of this column.
I don't know how to express for you understand. :( castoffs, i want to change color of column in datagrid during running project.
Can you have me a solution? Thank you so much.
What I have tried:
I added data:
private void add_data()
{
DataTable dt = new DataTable();
ListItem_nv.Clear();
dt = CMD_hengio.Show_hengio();
foreach (DataRow Row in dt.Rows)
{
Item_hengio item= new Item_hengio();
item.name_nv = Row[1].ToString();
item.ip_thuchien= Row[2].ToString();
item.time = ((DateTime)Row[3]).ToString("HH:mm:ss");// Row[3].ToString("HH:mm:ss");
item.date_start = ((DateTime)Row[4]).ToString("dd/MM/yyyy");
item.date_end =((DateTime)Row[6]).ToString("dd/MM/yyyy");
item.repeat = Row[5].ToString();
item.notes = Row[9].ToString();
item.status = Row[8].ToString();
item.tag_item = Row[0].ToString() + "*" + Row[7].ToString(); // add tag.
if (item.status == "Unfulfilled") item.Name_color = "Yellow";
if (item.status == "Processing") item.Name_color = "Green";
if (item.status == "Stop") item.Name_color = "Red";
if (item.status == "Pause") item.Name_color = "YellowGreen";
if (item.notes == "Error date")
{
item.Color_Notes = "Red";
}
if (item.notes == "Error timer")
{
item.Color_Notes = "Red";
}
else
item.Color_Notes = "#FF477067";
ListItem_nv.Add(item);
}
Datagrid.ItemsSource = ListItem_nv;
ICollectionView view = CollectionViewSource.GetDefaultView(ListItem_nv);
view.Refresh();
}
这是xaml:
this is xaml:
推荐答案
尝试在标记中嵌入格式
WPF XAML条件格式
Try embedding your formatting in the markup
WPF XAML Conditional Formatting
这篇关于在运行期间将颜色背景更改为WPF中datagrid中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!