我有一个绑定到数据网格的可观察集合。我在视图模型中也有一个color属性,我希望将数据网格中每一行的背景绑定到vm上的color属性。
发布于 2011-09-08 04:20:30
您可以在DataGrid
的RowStyle
中绑定Background
<DataGrid ...>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="{Binding MyBackground}"/>
</Style>
</DataGrid.RowStyle>
<!-- ... -->
</DataGrid>
如果MyBackground
是一个Brush
,这将会起作用。你在你的问题中提到你有一个Color
,如果是这样的话,你可以用这个代替
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="{Binding MyColor}"/>
</Setter.Value>
</Setter>
https://stackoverflow.com/questions/7339509
复制相似问题