We are working to develop a custom Add New Row for XamDataGrid, The image below is the design we want to achieve. However I will explain how we want to do it as well. The requirement is to show a button which is always visible with the text "Add Xyz", in case grid is empty it will be like a first row otherwise it will appear apparently as the last row in the grid. There are two possible solution we figured out
1) Modify the grid scrollviewer. When the user reach to the end of grid a datatrigger will be fired and the controltemplate for the scrollviewer will be show. This solution has its own limitations. If the grid height is less than min-width this behavior will fail. So this solution is out of question
2) Use Summary record presenter for this purpose. The issue with this technique is that we won't be able to show summaries if we override the behavior and styling of summaryrecordpresenter.
Is there any good solution for this problem? Your help will be appreciated. or we have to stick with either of the two mentioned
Hello Gottfried,
XamDataGrid has an Add New Record functionality that could be modified with a custom template for in order to add the button and text you would like to display. To achieve this you can set a style for the DataRecordPresenter with a DataTrigger checking if IsAddRecord property is true. In that scenario you can modify the default template e.g.
<Style TargetType="{x:Type igDP:DataRecordPresenter}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsAddRecord}" Value="true">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="This is customized Add New Record" Background="Aqua"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
There is a property AddNewRecordLocation which could be set to ‘OnBottom’ so the record is always displayed at the bottom.
Please feel free to let me know if you have any questions or concerns.
Hi Maria!
A sample project was missing in my previous reply. Here I'm attaching a sample project which depicts this issue. In sample project, the data for Customers is generated on each mouseover. Here we can see that those datarecords for which IsAddRecord property is not true also has the template of IsAddRecord. This issue could also be faced by scrolling the grid. Kindly have a look at the sample project.
I have reviewed the sample you attached and in this scenario the virtualization causes the DataRecordPresenters to be reused and trigger does not update after the data context has changed.
Another approach where for customizing the add new record is by modifying the DataRecordCellArea and collapsing the record selector when IsAddRecord property is true. This will solve the issue with the multiple add buttons.
<Style TargetType="{x:Type igDP:RecordSelector}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.IsAddRecord}" Value="True"> <Setter Property="Visibility" Value="Collapsed"/> </DataTrigger> </Style.Triggers> </Style> <Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Style.Triggers> <DataTrigger Binding="{Binding IsAddRecord}" Value="true"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Button Command="{Binding Path=DataContext.AddNewRow, RelativeSource={RelativeSource AncestorType=igDP:XamDataGrid}}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=igDP:XamDataGrid}}" HorizontalAlignment="Left" Content="Add New Record"/> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger> </Style.Triggers> </Style>
Please do not hesitate to ask if you have any other questions or concerns.
Thank you very much Maria, This resolved our issue.
Thank you for your feedback Gottfried.
I am glad that the issue is resolved.
My problem is some what similar in terms of adding a new row to xamdatagrid without actually using '+' and default row add functionality. I want to display few textfields/ combo fields as per entity in the bottom most row where user can enter/select row data. And then a Add button in the last column with those editable fields to add that row record to the xamdatagrid. Can you suggest how that can be accomplished.
Hello trun_gup,The default template for the DataRecordPresenter could be changed for the add new record setting a DataTrigger when IsAddNew property is true.Then you can use the EndEditModeAndCommitRecord command to commit the new record on button click: xamdatagrid.ExecuteCommand(DataPresenterCommands.EndEditModeAndCommitRecord);Let me know if you have any questions.