Xaml 如何在metro应用程序中更改listbox中某个特定listboxitem的背景色?
我正在开发一个c#/xaml metro应用程序 我有一个listbox,根据一个特定条件,我只想更改一个listboxitem背景颜色 我就是这样尝试的:-Xaml 如何在metro应用程序中更改listbox中某个特定listboxitem的背景色?,xaml,windows-8,listbox,microsoft-metro,listboxitem,Xaml,Windows 8,Listbox,Microsoft Metro,Listboxitem,我正在开发一个c#/xaml metro应用程序 我有一个listbox,根据一个特定条件,我只想更改一个listboxitem背景颜色 我就是这样尝试的:- if (lststudents != null) { foreach (StudentClass obj in lststudents) { if (obj.stutype == "Red House") { ///I am unable to typecast to listboxitem
if (lststudents != null)
{
foreach (StudentClass obj in lststudents)
{
if (obj.stutype == "Red House")
{
///I am unable to typecast to listboxitem, since it is of type student class
ListBoxItem lstbxbitem = (obj)ListBoxItem;
///
lstbxbitem.Background = new SolidColorBrush(Colors.Red);
}
}
}
lstbxbStudents.ItemsSource = lststudents ;
请注意:-我只想根据某些特定条件更改某些listboxitems的背景颜色
请让我知道我如何才能做到这一点
有哪些不同的选择
提前感谢。在列表框中使用DataTemplate,然后您可以创建DataTemplateSelector来设置列表框中特定项目的样式 您可以参考以下链接: 这里有一篇好文章:
您是否已完成上述任务,如果已完成,请告诉我您是如何完成的??因为我也陷入了同样的问题