Welcome to the Xceed Community | Help
Community Search  
More Search Options

Anyway To Have SelectedBackground Override Cell Color?

Sort Posts: Previous Next
  •  07-27-2012, 3:17 PM Post no. 32466

    Anyway To Have SelectedBackground Override Cell Color?

    I'm currently setting my cell background color based on certain criteria.  For example:

                <Style TargetType="{x:Type xcdg:DataCell}">
                    <Setter Property="HorizontalContentAlignment" Value="Right" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content}" Value="BAD DOCUMENT" >
                            <Setter Property="Background" Value="Red" />
                            <Setter Property="Foreground" Value="White" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>

    However, I notice this style seems to override the selected color.  Is that by design?  Any way to flip it?

     

     Thanks in advance!

  •  07-30-2012, 2:07 PM Post no. 32472 in reply to 32466

    Re: Anyway To Have SelectedBackground Override Cell Color?

    Hi Justin,

    The Background and Foreground colors will indeed override the selection colors.

    If you only want to apply a Style in a specific situation (in your case, only if the row is not selected), you can simply use a MultiDataTrigger and add any additional conditions that need to be met in order to apply your setters.

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  08-01-2012, 12:14 PM Post no. 32488 in reply to 32472

    Re: Anyway To Have SelectedBackground Override Cell Color?

    I changed my above style to:

     

                <Style TargetType="{x:Type xcdg:DataCell}">
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content}" Value="BAD DOCUMENT" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Background" Value="Red" />
                            <Setter Property="Foreground" Value="White" />
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>

    This rule only applies at the time the grid is painted.  When a user clicks on the grid, the red remains. Am I going to have to handle a click event?

  •  08-01-2012, 12:29 PM Post no. 32489 in reply to 32488

    Re: Anyway To Have SelectedBackground Override Cell Color?

    Hi Justin,

    Your condition states that the DataCell's IsSelected must be False, which is still the case if you select the row on a different DataCell. You should instead look at the DataRow's IsSelected value.

    Also, to make your Style more efficient in terms of performance, I would recommend adding a Condition on the FieldName. There is no point checking the DataCells of all the other Columns if the desired value will always only be in a specific Column.

    For example:

       <Style TargetType="{x:Type xcdg:DataCell}">
          <Style.Triggers>
             <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                   <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=FieldName}" Value="FieldA" />
                   <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content}" Value="BAD DOCUMENT" />
                   <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataRow}}, Path=IsSelected}" Value="False" />
                </MultiDataTrigger.Conditions>
                <Setter Property="Background" Value="Red" />
                <Setter Property="Foreground" Value="White" />
             </MultiDataTrigger>
          </Style.Triggers>
       </Style>

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  08-02-2012, 11:52 AM Post no. 32499 in reply to 32489

    Re: Anyway To Have SelectedBackground Override Cell Color?

    Even when selecting the cell in question it still wouldn't change.  Maybe because of read only?  However, setting the condition to the row worked like a charm.

    Excellent point on binding the specific field.  I'll be sure to do that from now on.

    Many thanks!

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.