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
295
Styles via code behind.
posted

i am to implement the style via code behind. i am able to create styles thru code behind.

my question is how can i create nested styles of xamdatagrid's DataRecordCellArea styles. for e.g ForegroundAlternateStyle.

what i found in generic themes of xamdatagrid.

how can i write this via code behind.

 <!--  _________________________ BlackForegroundStyle ______________________________________  -->
    <Style x:Key="{ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}">
        <Setter Property="TextBlock.Foreground" Value="#FF333333" />
    </Style>

here is how i m implementing

void ApplyRecordAreaStyle()
        {
            Style recordstyle = new Style(typeof(DataRecordCellArea));

            recordstyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundAlternateProperty, SelectedBackground));

            recordstyle.Setters.Add(new Setter (DataRecordCellArea.ForegroundAlternateStyleProperty ,????????));

            xamGrid.FieldLayoutSettings.DataRecordCellAreaStyle = recordstyle;

        }

Parents
No Data
Reply
  • 30945
    Verified Answer
    Offline posted

    Hello,

     

    Thank you for your post. I have been looking into it and you can create a style for the ContentPresenter and use it as a value for the setter for the ForegroundAlternateStyle property. Also if you wish to change the foreground of the alternated records I can suggest adding a Trigger to the style for the DataRecordCellArea for the IsAlternated property. Here is how you can implement the approach that I have mentioned:

     

    void ApplyRecordAreaStyle()
    {
        Style recordstyle = new Style(typeof(DataRecordCellArea));
    
        recordstyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundAlternateProperty, Brushes.Yellow));
              
        Style foregroundStyle = new Style(typeof(ContentPresenter));
        foregroundStyle.Setters.Add(new Setter(ContentPresenter.OpacityProperty, .7));
    
        recordstyle.Setters.Add(
            new Setter (DataRecordCellArea.ForegroundAlternateStyleProperty, foregroundStyle));
    
        //Trigger for setting the foreground for the alternated records
        Trigger trigger = new Trigger
        {
            Property = DataRecordCellArea.IsAlternateProperty,
            Value = true
        };
        trigger.Setters.Add(new Setter(DataRecordCellArea.ForegroundProperty, Brushes.Red));
    
        recordstyle.Triggers.Add(trigger);
    
        xamGrid.FieldLayoutSettings.DataRecordCellAreaStyle = recordstyle;
    
    }
    

    In you need any further assistance on the matter please do not hesitate to ask.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

Children