您可以将MouseDownorMouseUp事件添加到Grid,但这不会告诉您选择了哪个项目。您需要的是捕获 selection-changed 事件并更改所选项目的颜色。
此外,最好不要只在选择时更改颜色,最好在数据项中放置一个标志,告诉您它们是否已被触摸,然后根据该标志的值更新 XAML 中的颜色。
假设我们有这个视图模型:
public partial class MainWindow : Window
{
    public class Item : INotifyPropertyChanged
    {
        public string ItemText { get; set; }
        private bool _wasTouched;
        public bool WasTouched
        {
            get { return _wasTouched; }
            set { _wasTouched = value; OnPropertyChanged( "WasTouched" ); }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged( string name )
        {
            var handler = PropertyChanged;
            if( handler != null ) handler( this, new PropertyChangedEventArgs( name ) );
        }
    }
    public ObservableCollection<Item> Items { get; set; }
    public MainWindow()
    {
        InitializeComponent();
        Items = new ObservableCollection<Item>();
        Items.Add( new Item() { ItemText = "ugh." } );
        Items.Add( new Item() { ItemText = "whee" } );
        Items.Add( new Item() { ItemText = "nee" } );
        Items.Add( new Item() { ItemText = "ping" } );
        Items.Add( new Item() { ItemText = "neeeuuwwwop" } );
        this.DataContext = this;
    }
    private void ListBox_SelectionChanged( object sender, System.Windows.Controls.SelectionChangedEventArgs e )
    {
        ((sender as ListBox).SelectedItem as Item).WasTouched = true;
    }
}
有一个Item类有一些文本和一个布尔变量,指示它是否被触摸。该类实现INotifyPropertyChanged,以便当您更改它的值时WasTouched可以通知 XAML。我们创建了一些项目并将它们添加到对我们的 XAML 可见的集合中。此外,我们还有一个ListBox_SelectionChanged事件,它获取选定的项目并将其标记为已被触摸。
<ListBox ItemsSource="{Binding Items}" SelectionChanged="ListBox_SelectionChanged" >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <TextBlock Text="{Binding ItemText}"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red" />
            </Style.Resources>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Background" Value="Green"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding WasTouched}" Value="True">
                    <Setter Property="Background" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
在 XAML 中,我们告知ListBox项目和选择更改的处理程序。我们告诉它使用TextBox带有项目文本的 a 来显示每个项目。然后我们修改你已经提供的样式......我们通常将项目的背景设置为绿色,但是我们添加一个将背景更改为红色的DataTriggeron 。WasTouched
还有一个问题:列表使用蓝色背景绘制所选项目,覆盖您的背景颜色。这就是该Style.Resources部分的用途 - 它告诉 XAML 绘制具有红色背景的选定项目。