请问WPF DataGrid SelectionChanged事件中怎么获取行啊?dataGridRow.Background好像只有获取行后才设置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请问WPF DataGrid SelectionChanged事件中怎么获取行啊?dataGridRow.Background好像只有获取行后才设置相关的知识,希望对你有一定的参考价值。

datagridrow.background不需要获取行后才能设置的,比如你在trigger设置。
<Style TargetType="DataGridRow">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
再者,通过SelectionChanged获取datagridrow对象可以这么写(dg为DataGrid名称,t为你选中的实体对象)
private void dg_SelectionChanged(object sender, SelectionChangedEventArgs e)

TestDemo t = dg.SelectedItem as TestDemo;
if (t != null)

DataGridRow dr = (DataGridRow)(dg.ItemContainerGenerator.ContainerFromItem(t));
dr.Background = new SolidColorBrush(Colors.Yellow);

参考技术A ((System.Windows.Controls.DataGrid)(sender)).RowBackground
这是SelectionChanged事件的object sender 能获取到。

你是想做什么操作?

wpf mvvm DataGird 按钮事件

有个按钮放在 DataGrid 模板列中,比如说 修改 按钮,这个按钮放在DataGrid外面可以执行,但是在模板列中点击没反应,请问下是放在 DataGrid 模板列中 有什么 属性要设置的吗?求详细代码,初学者。。。

参考技术A 每行对应一个viewmodel,viewmodel里需要定义相应的command并绑定。 参考技术B 没有找过这个按钮

以上是关于请问WPF DataGrid SelectionChanged事件中怎么获取行啊?dataGridRow.Background好像只有获取行后才设置的主要内容,如果未能解决你的问题,请参考以下文章

wpf datagrid怎么得到焦点?用datagrid.focus()不行

请问WPF DataGrid SelectionChanged事件中怎么获取行啊?dataGridRow.Background好像只有获取行后才设置

C#,wpf,我想点击一个button时,将datagrid显示的数据保存到一个txt文档中,请问各位大侠,应该怎么弄呀

wpf datagrid怎么得到第一项焦点?然后在方向键上下移动

在WPF中使用DataGrid如何实现行冻结的功能

WPF DataGrid如何分页、导出Excle、打印(急)