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

时间:2017-11-28 15:58:31

标签: wpf

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

 private void DGImageList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
    object i = DGImageList.SelectedItem;
    //Set the selected row background colour to red
 }

1 个答案:

答案 0 :(得分:0)

好的,这就是你所需要的:

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;