DataGrid的WPF Datatrigger仅更改整行

时间:2010-07-22 14:45:41

标签: wpf xaml datagrid datatrigger

我有一个带有DataTrigger设置的DataGrid,所以当它的值为“UP”时,我希望触发器只改变'directionColumn'datagridcolumn中的背景。

到目前为止,我更新了整行。我也尝试在setter元素中放置'targetname',但这只是一个错误。请帮忙。

XAML:

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding}" Name="summaryReportDataGridDATE" RowDetailsVisibilityMode="VisibleWhenSelected" Width="330">
    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Direction}" Value="UP">
                    <Setter>
                        <Setter.Property>Background</Setter.Property>
                        <Setter.Value>Red</Setter.Value>
                    <!--<Setter Property="Background" Value="Red" TargetName="directionColumn"/>-->
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.CellStyle>
    <DataGrid.Columns>
        <!--<DataGridTemplateColumn x:Name="dateColumn" Header="Date" Width="100" CanUserReorder="False" CanUserSort="False" FontFamily="Arial Rounded MT" >
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <DatePicker SelectedDate="{Binding Path=Date, Mode=OneWay}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>-->

        <DataGridTextColumn x:Name="dateColumn" Binding="{Binding Path=Date, StringFormat={}{0:dd/MM/yyyy}}" Header="Date"  Width="80" CanUserReorder="False" CanUserSort="False" FontFamily="Arial Rounded MT"/>
        <DataGridTextColumn x:Name="closeColumn" Binding="{Binding Path=ClosingPrice}" Header="ClosingPrice" Width="80" CanUserReorder="False" CanUserSort="False" FontFamily="Arial Rounded MT" />
        <DataGridTextColumn x:Name="directionColumn" Binding="{Binding Path=Direction}" Header="Direction"  Width="80" CanUserReorder="False" CanUserSort="False" FontFamily="Arial Rounded MT" />
        <DataGridTextColumn x:Name="resultColumn" Binding="{Binding Path=Result}" Header="Result"  Width="80" CanUserReorder="False" CanUserSort="False" FontFamily="Arial Rounded MT"  />
    </DataGrid.Columns>
</DataGrid>

1 个答案:

答案 0 :(得分:6)