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
645
How to change background color in xamGrid
posted

Hi There,

I use xamGrid to display some pnl number and based on value background color of cell should be red or green. I know how to do in XamDataGrid,

=============================

<igDP:XamDataGrid x:Name="_dataGrid" Theme="[Current]">

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

                  <igDP:Field Name="TodaysPnl" Label="TodaysPnl" Width="110" >
                        <igDP:Field.Settings>
                            <igDP:FieldSettings>
                                <igDP:FieldSettings.CellValuePresenterStyle>
                                    <Style TargetType="{x:Type igDP:CellValuePresenter}">
                                        <Setter Property="Background"
                                                    Value="{Binding Path=Cells[TodaysPnl].Value, Converter={StaticResource greaterThanZeroConverter}}">
                                        </Setter>
                                        <Setter Property="Foreground" Value="White" />
                                    </Style>
                                </igDP:FieldSettings.CellValuePresenterStyle>
                            </igDP:FieldSettings>
                        </igDP:Field.Settings>
                    </igDP:Field>

=======================================

I want to do same thing in xamGrid. I don't know how to do it. Does anyone know how can I  do it. Here is the code,

<ig:XamGrid x:Name="_dataGrid" AutoGenerateColumns="false" ColumnWidth="*"  >

.................

............

<ig:XamGrid.Columns>

       <ig:TextColumn Key="TotalTodaysPnl" FormatString="{}{0:C}">
                <ig:TextColumn.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="TodaysPnl" />
                    </DataTemplate>
                </ig:TextColumn.HeaderTemplate>
                <!--<ig:TextColumn.CellStyle>
                    <Style>
                       
                        </Setter>
                    </Style>
                </ig:TextColumn.CellStyle>-->
                
            </ig:TextColumn>

</ig:XamGrid.Columns>
</ig:XamGrid>

Thanking you in advance for your help.

Nasir

Parents
  • 645
    posted

    Hi There,

    I was able to change the style of cell. But now I have a strange issue. Somehow it only changes background color for alternate row.

    Here is some code,

    ======================================================================

    <Style x:Key="NegativePnl" TargetType="ig:CellControl" >
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Background" Value="Red" />
            </Style>
            <Style x:Key="PositivePnl" TargetType="ig:CellControl" >     
                <Setter Property="FontSize" Value="12"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Background" Value="Green" />
     </Style>

    <ig:XamGrid x:Name="_dataGrid" AutoGenerateColumns="false" ColumnWidth="*" CellControlAttached="_dataGrid_CellControlAttached" >

    private void _dataGrid_CellControlAttached(object sender, Infragistics.Controls.Grids.CellControlAttachedEventArgs e)
    {
                double value = e.Cell.Row.Data as double;

                if (null != value)
                {
                    SetCellStyle(value, e.Cell);
                }
    }

    private void SetCellStyle(double value, Infragistics.Controls.Grids.Cell currentCell)
    {
                if(value < 0)
                    currentCell.Style = Resources["NegativePnl"] as Style;
                else
                    currentCell.Style = Resources["PositivePnl"] as Style;
    }

    ====================================================================

    Please let me know if is there anything needs to be done to fix this.

    Thanks

    Nasir

Reply Children