我想更改 UWP 的 ListView
上项目的前景
。
我正在使用:
int i_DeleteRow = ListView1.SelectedIndex;
var item = ListView1.Items[i_DeleteRow] as ListViewItem;
if (item != null)
{
item.Foreground = new SolidColorBrush(Colors.Red);
}
但是使用此代码item
始终为空。
如有任何帮助,我们将不胜感激。
最佳答案
您需要使用ItemContainerGenerator.ContainerFromIndex
。它返回一个 DependencyObject
,然后您可以将其转换为 ListBoxItem
并使用 ListBoxItem
的属性,例如 Foreground
:
ListViewItem item = (ListViewItem)(ListView1.ItemContainerGenerator.ContainerFromIndex(ListView1.SelectedIndex));
if (item != null)
{
item.Foreground = new SolidColorBrush(Colors.Red);
}
关于c# - 更改 ListView 的前景项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38573581/