Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Applying CellValuePresenterStyle breaks funtionality
posted

I am applying a style to CellValuePresenter but when the row is highlighted or selected the style is ignored. For example, I am using the following XAML to change the foreground color when it contains a specific value. It works until the user rolls the mouse over the row or selects it. Then the style is ignored.

<Window x:Class="XamChildGridLabel.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:XamChildGridLabel"
        xmlns:igDP="http://infragistics.com/DataPresenter"
        mc:Ignorable="d"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <igDP:XamDataGrid DataSource="{Binding Level1}" GroupByAreaLocation="None">
            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings AllowSummaries="False" SummaryUIType="SingleSelect" LabelTextAlignment="Center" AllowEdit="False"/>
            </igDP:XamDataGrid.FieldSettings>
            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout Description="Level 1" Key="Level1">
                    <igDP:FieldLayout.Fields>
                        <igDP:TextField Label="Text" Name="Text">
                            <igDP:TextField.CellValuePresenterStyle>
                                <Style TargetType="igDP:CellValuePresenter">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding DataItem.Text}" Value="Text 1">
                                            <Setter Property="Foreground" Value="Red"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </igDP:TextField.CellValuePresenterStyle>
                        </igDP:TextField>
                    </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>
    </Grid>
</Window>

namespace XamChildGridLabel
{

    public partial class MainWindow : Window
    {
        public class cLevel1
        {
            public String Text { get; set; }
            public cLevel1(String t)
            {
                this.Text = t;
            }
        }

        public List<cLevel1> Level1 { get; set; }

        public MainWindow()
        {
            Level1 = new List<cLevel1>() { new cLevel1("Text 1"), new cLevel1("Text 2") };
            InitializeComponent();
        }
    }
}

  • 27860
    Verified Answer
    Offline posted

    Hello Terry,

    I have been investigating into this behavior you are seeing, and there are quite a few different properties on the CellValuePresenter that effect the foreground color depending on the state of the cell or the record that owns the cell. For example, there is the ForegroundHoverStyle, ForegroundSelectedStyle, etc. properties.

    In the CellValuePresenter, these properties expect a Style targeting ContentPresenter, in which you can use a Setter to set the TextElement.Foreground property to have it applied. I would recommend setting these different properties to further control the foreground of your cells. I am attaching a sample project to demonstrate usage of these properties to prevent foreground color changes on hover, selection, and activation. I hope it helps you.

    Please let me know if you have any other questions or concerns on this matter.

    XDGCellValuePresenterStyleCase.zip