【发布时间】:2012-09-13 11:05:41
【问题描述】:
我有一个DataGrid,我想在其中根据ItemSource的值来改变一行的背景,所以我需要传递当前的item,但是我不知道怎么做。
我正在这样做:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource myDataGridBackgroundMultiValueConverter}">
<MultiBinding.Bindings>
<Binding ElementName="ucPrincipal" Path="DataContext.MyProperty01FromDataContext"/>
<Binding ElementName="ucPrincipal" Path="DataContext.MyProperty02FromDataContext"/>
<Binding ElementName="ucPrincipal" Path="DataContext.MyProperty03FromDataContext"/>
<Binding ElementName="dgdMyGrid" Path="CurrentItem"/>
</MultiBinding.Bindings>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowStyle>
DataGrid 在ViewModel 中具有MyDataClass(具有许多属性)的集合,如ItemsSource。我需要将带有行信息的 MyDataClass 传递给转换器。
CurrentItem 不起作用,因为我总是收到 null。
其他参数都ok。
【问题讨论】:
标签: wpf xaml data-binding datagrid