本文共 676 字,大约阅读时间需要 2 分钟。
private void MenuItem_Click(object sender, RoutedEventArgs e)
string header = (sender as MenuItem).Header.ToString();
ListBoxItem selectedListBoxItem = this.listBox.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem;
if (selectedListBoxItem == null)
if (header == "Add Color")
selectedListBoxItem.Background = new SolidColorBrush(Colors.Red);
selectedListBoxItem.Background = new SolidColorBrush(Colors.Black);
//To highlight the tapped item just use something like selectedListBoxItem.Background = new SolidColorBrush(Colors.Green);
转载于:https://www.cnblogs.com/hebeiDGL/archive/2011/11/20/2256281.html