Hi,
I want to edit the Add New Row template of XAMDataGrid to give a different background colour to the AddNewRow section. As per Infragistics samples, similar thing can be done in XamGrid using AddNewRowItemTemplate, AddNewRowEditorTemplate.
Is there option in XamDataGrid to do the same?
Thanks,
SK
Hello Sandeep,
I am just checking your progress on this issue. Please do not hesitate to let me know if you have any further questions on this matter.
I have been looking into your post. If I have understood correctly you want the style for the CellValuePresenter to apply to all of the field in the xamDataGrid and you do not want to set it to all of the fields separately. If this is the case I can suggest to remove the ‘Key’ for the style for the CellValuePresenter: x:Key="CellValuePresenterStyle". This way the style would automatically apply to all of the existing fields.
Please do not hesitate to let me know if you have any further questions on this matter.
Hi Gergana,
Thanks for your quick responses. I can now see the reason why your solution was not working properly in my environment. Here I am setting the common cell properties like Height etc in the CellValuePresenterStyle, which seems to be preventing the application of the themes on the existing rows in the Grid. Thanks for the resolution of my original issue around styling the AddNewRecord Row. Could you suggest some way to sepcify all these common cell properties at one place rather then duplicating them under the FieldSettings under each field.
I am attaching below the modified copy of your sample XAML which illustrate my point on CellValuePresenterStyle, which prevents application of IGTheme in this case.
Sandeep
<Window x:Class="DataGrid_AddNewRowTemplate.MainWindow"xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns:local="clr-namespace:DataGrid_AddNewRowTemplate"
xmlns:igDP=http://infragistics.com/DataPresenter
Title="MainWindow"
Height="350"
Width="525">
<Window.Resources>
<local:DataUtil x:Key="Data" />
<Style x:Key="DataRecordCellAreaStyle" TargetType="{x:Type igDP:DataRecordCellArea}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsAddRecord}"
Value="True">
<Setter Property="Background"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="CellValuePresenterStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Height" Value="40" />
</Window.Resources>
<Grid>
<igDP:XamDataGrid x:Name="DataGrid"
Theme="IGTheme"
DataSource="{Binding Source={StaticResource Data}, Path=Products}"
FieldLayoutInitialized="DataGrid_FieldLayoutInitialized">
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AddNewRecordLocation="OnTop"
AllowAddNew="True"
AutoGenerateFields="False"
DataRecordCellAreaStyle="{StaticResource DataRecordCellAreaStyle}"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Name="ProductID"
Label="ProductID">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource CellValuePresenterStyle}" />
</igDP:Field.Settings>
</igDP:Field>
<igDP:Field Name="ProductName"
Label="ProductName">
<igDP:Field Name="CategoryID"
Label="CategoryID">
<igDP:Field Name="QuantityPerUnit"
Label="QuantityPerUnit">
<igDP:Field Name="UnitPrice"
Label="UnitPrice">
<igDP:Field Name="UnitsInStock"
Label="UnitsInStock">
<igDP:Field Name="UnitsOnOrder"
Label="UnitsOnOrder">
<igDP:Field Name="ReorderLevel"
Label="ReorderLevel">
<igDP:Field Name="Discontinued"
Label="Discontinued">
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</Grid>
</
Window>
I have been looking into your issue. The template you are referring to is part of the xamGrid and is not implemented in the xamDataGrid. Currently the best approach to style the AddNewRecord area is to use the style I have used in the sample application, attached in one of my previous posts. Here is the style:
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<DataTrigger Binding="{Binding Path=IsAddRecord}" Value="True">
<Setter Property="Background" Value="Red"/>
Please note, that the setters, that apply only to the AddNewRecord area are inside the DataTrigger. If you set a property inside the trigger, it would apply to all of the other records.
Thanks fro your reply. Here I am assuming that Add new Record row at the top is seperate from the rest of the Content/AlreadyExisting rows below and should be customizable seperatly. The issue here is that when we apply style to "DataRecordCellArea" then it is applied to even the content/existing rows as well.
In XamGrid, You have provided the "AddNewRowTemplate" for new Row at the top and applying style to this row won't change the style of Content/AlreadyExisting rows. i.e. theme continue to work on already added rows, whereas, my custom style will work only on the New Row Line at top.
Is there any way in XamDataGrid that I can use this XamGrid like NewRowStyling with theme continue to be applied on the already existing rows?
Many Thanks,