WpfToolkit的DataGrid:高亮修改的行 [英] WpfToolkit DataGrid: Highlight modified rows
问题描述
有没有一种方法,以突出显示所有在DataGrid中修改的行?由于网格绑定到 System.Data.DataTable
我想我也许可以每行的颜色绑定到它的RowState(下面的例子),但是那并不是' :T似乎工作
任何想法
的xmlns:数据=CLR - 命名空间:System.Data这;装配= System.Data这
<风格X:关键=DataGridRowStyle的TargetType ={X:类型工具箱:DataGridRow}>
< Style.Triggers>
<触发属性=IsSelectedVALUE =真正的>
< setter属性=背景VALUE =蓝/>
< /触发>
< DataTrigger绑定={结合的RowState}VALUE ={X:静态数据:DataRowState.Modified}>
< setter属性=背景VALUE =浅黄/>
< / DataTrigger>
< /Style.Triggers>
< /样式和GT;
< DataGrid.RowStyle>
<风格的TargetType =DataGridRow>
< Style.Triggers>
< DataTrigger绑定={结合的RowState}VALUE ={X:静态数据:DataRowState.Modified}>
< setter属性=背景VALUE =浅黄/>
< / DataTrigger>
< /Style.Triggers>
< /样式和GT;
< /DataGrid.RowStyle>
更新结果
你还公布后您的XAML中,很明显,这个问题是不是在XAML中找到。我已经很快看了MSDN的数据表类,我不能看到让WPF检测的RowState
- 特性的变化的机制。因此,直接绑定到这个属性不会给你可靠的结果。结果
看来你要包装你的数据项。我建议做一个视图模型的项目,并补充说,如果说该行已与变更通知( INotifyPropertyChanged的
或DP)更改的属性并绑定到该属性。肯定会有还其他的替代品,但国际海事组织创建每个项目一个VM是在大多数情况下,最好的解决方案。
Is there a way to highlight all the modified rows on a DataGrid? Since the grid is bound to a System.Data.DataTable
I figured I might be able to bind the colour of each row to it's RowState (example below), but that doesn't seem to work.
Any ideas?
xmlns:data="clr-namespace:System.Data;assembly=System.Data"
<Style x:Key="DataGridRowStyle" TargetType="{x:Type toolkit:DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="Blue" />
</Trigger>
<DataTrigger Binding="{Binding RowState}" Value="{x:Static data:DataRowState.Modified}">
<Setter Property="Background" Value="LightYellow" />
</DataTrigger>
</Style.Triggers>
</Style>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding RowState}" Value="{x:Static data:DataRowState.Modified}">
<Setter Property="Background" Value="LightYellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Update
After you have posted also your xaml, it's obvious that the problem is not to be found in the xaml. I have shortly looked at msdn for the DataTable-class and I can not see a mechanism that let WPF detect changes of the RowState
-property. Therefore, direct binding to this property will not give you reliable results.
It seems that you have to wrap your data items. I recommend to make a ViewModel for the items and add a property that says if the row has changed with change notification (INotifyPropertyChanged
or DP) and bind to this property. Surely there will be also other alternatives, but IMO creating a VM per item is in most cases the best solution.
这篇关于WpfToolkit的DataGrid:高亮修改的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!