当备用reocrd为true时,Xamdatagrid设置所选的背景颜色

时间:2015-11-18 16:20:05

标签: infragistics

我目前面临的问题是,当备用行为真时将背景颜色设置为黄色

我有网格,其中几列背景设置为不同的颜色。我已设置highlightlight更改行是真的。我在选择记录时也设置了黄色背景。

 <Window.Resources>
    <ObjectDataProvider x:Key="CarData" ObjectType="{x:Type Cars:CarsBusinessLogic}" MethodName="GetCars" />

    <Style TargetType="{x:Type igDP:DataRecordCellArea}" >
        <Setter Property="BackgroundSelected" Value="#FFDB4C"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsSelected}" Value="False">
                <Setter Property="BackgroundActive" Value="Transparent"/>
                <Setter Property="BorderActiveBrush" Value="Transparent"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type igDP:DataRecordPresenter}" >
        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="drp_PreviewMouseLeftButtonDown"/>
    </Style>

    <Style TargetType="{x:Type igDP:DataRecordCellArea}" x:Key="RecordAlignment">
        <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
        <Setter Property="HorizontalAlignment" Value="Center"></Setter>
        <Setter Property="VerticalAlignment" Value="Top"></Setter>
        <Setter Property="VerticalContentAlignment" Value="Top"></Setter>
        <Setter Property="BackgroundActive" Value="#FFDB4C"/>
        <Setter Property="BackgroundSelected" Value="#FFDB4C"/>
        <Setter Property="BackgroundHover" Value="#7092BE"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding DataItem.Hovered}" Value="True">
                <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=BackgroundHover}"/>
                <Setter Property="BackgroundAlternate" Value="{Binding RelativeSource={RelativeSource Self}, Path=BackgroundHover}"/>
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="FontWeight" Value="Bold"></Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=IsSelected}" Value="False">
                <Setter Property="BackgroundActive" Value="Transparent"/>
                <Setter Property="BorderActiveBrush" Value="Transparent"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="ColumnStyle1" TargetType="{x:Type igDP:CellValuePresenter}" >
        <Setter Property="Background" Value="#D8E4BC"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
                <Setter Property="Background" Value="Transparent"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                <Setter Property="Background" Value="Transparent"/>
            </DataTrigger>

            <DataTrigger Binding="{Binding DataItem.IsActive}" Value="True">
                <Setter Property="Background" Value="Transparent"/>
            </DataTrigger>

            <DataTrigger Binding="{Binding Path=IsAlternate,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={ x:Type igDP:DataRecordCellArea}} }" Value="True">
                <Setter Property="Background" Value="#EFF7DB" />
            </DataTrigger>

            <DataTrigger Binding="{Binding DataItem.Hovered}" Value="True">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="FontWeight" Value="Bold"></Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>


</Window.Resources>
<Grid>
    <ScrollViewer Name="view1">

        <igDP:XamDataGrid 
            Width="490" DataSource="{Binding Source={StaticResource CarData}}" HorizontalAlignment="Left" Name="xamDataGrid1" VerticalAlignment="Top"   >

            <igDP:XamDataGrid.Resources>
                <Style TargetType="{x:Type igDP:RecordListControl}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type igDP:RecordListControl}">
                                <ScrollViewer  CanContentScroll="true"
                      VerticalScrollBarVisibility="Disabled"
                      HorizontalScrollBarVisibility="Disabled"    >
                                    <ItemsPresenter/>
                                </ScrollViewer>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </igDP:XamDataGrid.Resources>

            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings AllowEdit="False" AllowFixing="No"
                                    CellClickAction="SelectRecord" 
                                CellHeight="25" AutoSizeOptions="All"
                                    AutoSizeScope="RecordsInView" 
                                    CellContentAlignment="LabelAboveValueAlignLeft" />
            </igDP:XamDataGrid.FieldSettings>

            <igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:FieldLayoutSettings  SelectionTypeRecord="Single" ></igDP:FieldLayoutSettings>
            </igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:XamDataGrid.FieldLayouts>

                <igDP:FieldLayout Key="BrandLevel" Tag="Brand" >
                    <igDP:FieldLayout.Settings>
                        <igDP:FieldLayoutSettings  HighlightAlternateRecords="True"  ></igDP:FieldLayoutSettings>
                    </igDP:FieldLayout.Settings>

                    <igDP:FieldLayout.Fields>
                        <igDP:Field Name="Make"/>
                        <igDP:Field Name="Model" />
                        <igDP:Field Name="BasePrice" >
                            <igDP:Field.Settings>
                                <igDP:FieldSettings CellMinWidth="50"   CellValuePresenterStyle="{StaticResource ColumnStyle1}">
                                </igDP:FieldSettings>
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="Mileage"/>



                    </igDP:FieldLayout.Fields>
                    </igDP:FieldLayout>
                </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>

    </ScrollViewer>
</Grid>

1 个答案:

答案 0 :(得分:1)

要在选择备用记录时保持黄色背景,请将CellValuePresenter背景设置为透明。这样的事情可以解决问题。

<Style x:Key="CellBackgroundStyle" TargetType="{x:Type igDP:CellValuePresenter}" >
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
            <Setter Property="Background" Value="Transparent"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
            <Setter Property="Background" Value="Transparent"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}}" Value="True">
            <Setter Property="Background" Value="Transparent"/>
        </DataTrigger>
    </Style.Triggers>
</Style>