我需要更改listBox中项目的颜色,这些是由类添加的,而XAML在一天中的某些小时之间使用绑定我需要更改添加到ListBox的项目的颜色,示例在评论中,使用DateTime,但我无法工作。 来自哥伦比亚的问候
public class Class1
{
public String Link { get; set; }
public String Horario { get; set; }
public String Foto { get; set; }
public Class1(String link, String horario, String foto)
{
this.Link = link;
this.Horario = horario;
this.Foto = foto;
}
}
}
private void MainPage_loaded(object sender, RoutedEventArgs e)
{
DateTime dt11AM = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 0, 0);
DateTime dt1130AM = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 11, 30, 0);
List<Class1> milista = new List<Class1>();
milista.Add(new Class1("B1", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));
milista.Add(new Class1("B2", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));
milista.Add(new Class1("B3", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));
milista.Add(new Class1("B5", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));
milista.Add(new Class1("B6", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));
milista.Add(new Class1("B7", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));
milista.Add(new Class1("B8", "L/S 5:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));//
milista.Add(new Class1("B9", "L/S 7:00 am-8:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));// green color "b9" and "L/S 7:00 am-11:00 pm D/F 5:00 am-11:00 pm"
milista.Add(new Class1("B10", "L/S 6:00 am-11:00 pm D/F 5:00 am-11:00 pm", "Images/Zona_B.jpg"));//Red , only "B10" element
ListaObjeto.ItemsSource = milista;
//if (DateTime.Now < dt11AM)
// ListaObjeto.ItemContainerGenerator.ContainerFromIndex(0);
// ListBoxItem.ForegroundProperty = new SolidColorBrush(Colors.Yellow));
}