如何在双击时更改WPF DataGrid行的颜色?

如何在双击时更改WPF DataGrid行的颜色?,wpf,Wpf,拜托,有人能帮我吗? 我的代码如下: private void DGImageList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { object i = DGImageList.SelectedItem; //Set the selected row background colour to red } 好的,这里是您所需要的: private void DGImageList_MouseDoubleC

拜托,有人能帮我吗? 我的代码如下:

 private void DGImageList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
    object i = DGImageList.SelectedItem;
    //Set the selected row background colour to red
 }
好的,这里是您所需要的:

private void DGImageList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    var index = ((DataGrid)sender).SelectedIndex;// 
    DataGridRow row = (DataGridRow)((DataGrid)sender).ItemContainerGenerator.ContainerFromIndex(index);
    row.Background = new SolidColorBrush(Colors.Red);
}
参考资料:

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

问题在标题中。这就是“如何在鼠标双击时更改wpf datagrid行的背景/前景颜色?”看,这是一个在Eventso上更改颜色的示例。建议的代码适用于DataGrid_LoadingRow事件,但我需要用于鼠标双击事件。我基本上是在尝试实现以下功能:private void dgmagelist_MouseDoubleClick(对象发送器,MouseButtonEventArgs e){DataGridRow gridRow=e.Row;DataRow=(gridRow.DataContext作为DataRowView)。Row;gridRow.Background=new solidcolorbush(Colors.Green);}你的帖子已经被编辑了,看看是否有什么东西在等待批准,这样他的代码就更容易被看到。我在想你的问题,当你点击网格时,行的颜色已经改变了,你真正需要什么?如果双击另一行会发生什么?你是天才塞尔索。非常感谢你的帮助。今晚我会睡个好觉!欢迎你,马克作为答案,做个美梦。:)