使用wpf以编程方式更改datagrid选定的行颜色?

时间:2010-12-22 15:14:19

标签: wpfdatagrid

我想在后面的代码中动态更改所选的行颜色。我正在使用Visual Studio 2008.任何人都可以帮忙这样做吗?

1 个答案:

答案 0 :(得分:0)

Dim selectedItem As New Style(GetType(DataGridCell))
    Dim triggerIsSelected As New Trigger() With {.[Property] = DataGridCell.IsSelectedProperty, .Value = True}
    triggerIsSelected.Setters.Add(New Setter(DataGridCell.BackgroundProperty, System.Windows.Media.Color.Red))
    selectedItem.Triggers.Add(triggerIsSelected)
    Datagrid1.CellStyle = selectedItem