繁体   English   中英

基于绑定到DataView的DataGrid中单元格的值的DataTrigger

[英]DataTrigger based on value of cell in DataGrid bound to DataView

我试图根据其中一个单元格的当前值更改DataGrid中行的背景。 我的研究得出的结论是,您可以使用DataTrigger进行此操作,但我似乎无法编写不会出错的绑定表达式。

本节的XAML如下:

<DataGrid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding TodaysBets}" ColumnWidth="*" CanUserAddRows="False" AutoGenerateColumns="False" TextBlock.FontSize="14" IsReadOnly="True">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Matched}" Value="false"> //This binding expression failing
                    <Setter Property="Background" Value="LightCoral"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
   </DataGrid.RowStyle>
   <DataGrid.Columns>
       ......DataGridColumn Definitions here all bound to "TodaysBets"
   </DataGrid.Columns>
</DataGrid>

匹配的列是一个布尔值,它不断地扔出去一样找不到财产上的匹配对象DataRowView的绑定错误。 任何人都可以帮我尝试一切吗?

它抛出的错误是这样的:

System.Windows.Data Error: 40 : BindingExpression path error: 'Matched' property not found on 'object' ''DataRowView' (HashCode=4932563)'. BindingExpression:Path=Matched; DataItem='DataRowView' (HashCode=4932563); target element is 'DataGridRow' (Name=''); target property is 'NoTarget' (type 'Object')

找到解决方案。 我要做的就是将绑定表达式更改为:

Binding="{Binding Row.Matched}" 

因为绑定是在选择DataRowView,所以我必须使绑定表达式选择基础DataRow,然后才能绑定到正确的属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM