【发布时间】:2014-04-15 14:59:38
【问题描述】:
我有一个包含客户类型列表的列表框。所以我的 Listbox.Items 不再是 ListItem 类型,而是 customer 类型。
我在客户字段中有一个 isActive 标志,我想知道如果 isActive 为真,我将如何将背景颜色设置为红色。
目前我已经尝试过了,但它不起作用,因为我无法让客户输入 ListBoxtem
List<object> inactiveCustomers = new List<object>();
foreach (Customer item in ListBoxCustomers.Items)
{
if (!item.IsActive)
{
inactiveCustomers.Add(item);
int index = ListBoxCustomers.Items.IndexOf(item);
ListBoxItem x = (ListBoxItem)ListBoxCustomers.Items[index];
x.Background = Brushes.Red;
}
}
编辑: 每当我取消选择适用于活跃客户的复选框时,我都会调用一个执行上述代码的方法。每当我取消选中 Active Checkbox 时,我都会遍历客户并显示所有客户,此时我想更改非活动的背景颜色以区分哪些是非活动/活动的
【问题讨论】: