您正在修改
Application.Current.Resources
,这将影响所有ListView。改为更改控件实例上的资源:
private void ListBoxQuestionAnswers_OnSelectionChanged (object sender, SelectionChangedEventArgs e)
{
if (ListBoxQuestionAnswers.SelectedIndex == Question.CorrectAnswerIndex)
{
ListBoxQuestionAnswers.Resources ["SystemControlHighlightListAccentLowBrush"] = new SolidColorBrush (Colors.Green);
ListBoxQuestionAnswers.Resources ["SystemControlHighlightListAccentMediumBrush"] = new SolidColorBrush (Colors.Green);
}
else
{
ListBoxQuestionAnswers.Resources ["SystemControlHighlightListAccentLowBrush"] = new SolidColorBrush (Colors.Red);
ListBoxQuestionAnswers.Resources ["SystemControlHighlightListAccentMediumBrush"] = new SolidColorBrush (Colors.Red);
}
}
每一个
FrameworkElement
可以拥有自己的资源,在访问父元素(如页面或应用程序)以查找合适的源之前,将首先查看这些资源。