I want to to add some blank space in between 2 rows of xamdatagrid grid. Can you please suggest how can I achieve this?
Hello Richa,
You can add space between two records by simply increasing the bottom (or top) margin of one of the records. It would really depend on the exact functionality you are looking for and under what conditions (if any) this visual change should be triggered.
For example:
Approach (1) Space between every 2 records.
<Style TargetType="igDP:DataRecordPresenter"> <Setter Property="Margin" Value="0,0,0,10" /></Style>
Approach (2) Space between a specific record and the one beneath it.This will create a blank space between the record whose DataItem.Name property is "Item 7" and the record beneath it.
<Style TargetType="igDP:DataRecordPresenter"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Record.DataItem.Name, RelativeSource={RelativeSource Self}}" Value="Item 7"> <Setter Property="Margin" Value="0,0,0,10" /> </DataTrigger> </Style.Triggers></Style>
I have attached a sample application that demonstrates the approaches from above.
If you have any questions, please let me know.
My requirement is like I have a hierarchical xamdatagrid and I want a border for each parent row with its child rows
and each of the parent rows should have some blank spacing in between . I have attached the image for reference. I also want to allow drag and drop functionality between the rows. Please let me know how can I achieve this
Thank you for the screenshot you have provided.
The records from the image you have attached seem to be grouped rather than having hierarchical (nested) data.In order to create blank space between the GroupBy records, I can suggest you use the same approach as in my previous reply by increasing the margin of every GroupByRecordPresenter.
<Style TargetType="igDP:GroupByRecordPresenter"> <Setter Property="Margin" Value="0,0,0,10" /></Style>
Both for hierarchical data and grouped data in the XamDataGrid, the parent record presenter and its children do not have a unique parent element that we can use for the border. In order to create a border that surrounds the parent and its children, I can suggest you retemplate the default styles of the respective RecordPresenters according to your logic.
In order use drag & drop for DataRecords in hierarchical XamDataGrid, I can suggest you take a look at the following thread, where the same issue is discussed and a sample is provided. You can use it as a starting point for your application and implement it analogically for the GroupByRecordPresenters (if this is the desired functionality).
Hi
Many thanks for your response, yes I know the image provided is achieved through grouping but I need this without using grouping. I need a border around each parent row and spacing in between the parent rows as mentioned earlier. But since I am new to WPF can you please provide a sample of how I can do this through templating?
Also, I was able to perform drag and drop of the rows.
Thanks
Richa
In order to display a border around the child records and their parent records along with spacing between every couple of parent records, we will have to manually control the Margins and the BorderThickness properties of the DataRecordCellArea for the records from both the parent and the child FieldLayout.I have attached a sample application that demonstrated the behavior from above. (refer to the App.xaml file )
In order to display the border around the parent record only, we can simply remove setters for the BorderThickness, BorderBrush and CornerRadius properties for the child DataRecordCellArea elements and their respective LabelPresenters.
For more details on the matter, I can suggest you take a look at the following thread, where the same issue has been discussed.If you have any questions, please let me know.
In order to avoid using code-behind when applying the border around the child panel, I can suggest you create a ResourceDictionary that contains all the styles that are related to the Border and Margin manipulations. This way by including the dictionary inside the App.xaml, we can apply all the necessary settings at application level.
// Border around child panel (MyDictionary.xaml)
<Style TargetType="Border"> <Style.Triggers> <Trigger Property="Name" Value="PART_NestedContentSite"> <Setter Property="BorderBrush" Value="Red" /> <Setter Property="BorderThickness" Value="1,0,1,1" /> </Trigger> </Style.Triggers></Style>
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="MyDictionary.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
Another approach I can suggest you is to get the default style of the respective elements (DataRecordPresenter, DataRecordCellArea, etc.) and manually modify them according to the desired functionality.
I have attached a sample application that demonstrates the initial approach from above. (I have commented some methods from the original code you have provided in order to build the application successfully, you can manually revert these changes.)
Hi,
I need 1 more favor . Since my code is in MVVM framework, so can you please suggest how can I use ths code in MVVM, as below lines of code in xaml.cs file is violating the MVVM famework:
private void grdElementCollection_RecordExpanded(object sender, Infragistics.Windows.DataPresenter.Events.RecordExpandedEventArgs e) { var drp = DataRecordPresenter.FromRecord(e.Record) as DataRecordPresenter; var nestedSite = Utilities.GetDescendantFromName(drp, "PART_NestedContentSite") as Border; if (nestedSite != null) { nestedSite.BorderThickness = new Thickness(1, 0, 1, 1); nestedSite.BorderBrush = Brushes.Red; } }
Thank you for your feedback.
I am glad to know that I was able to help you achieve the functionality you were looking for. I believe this thread can help other people looking for a similar solution.
Thank you for using Infragistics components.
Thia solution works well, thanks for all the help
Thank you for the sample application you have provided.
I have attached a modified version of your sample by including the changes from my sample, so both the parent and its children have a border around them. You can use the UseNestedPanels property by setting it to True. This will render the child records as actual visual children (in a nested panel) of the parent DataRecordPresenter.
Please note when using the MetroDark theme, some further manipulations and logic should be done since the theme itself introduces lots of display and layout behaviors. In this case I can suggest you use the default styles of the control for the MetroDark theme and after retemplating the elements accordingly, you can include the theme files in your application.
I have attached a sample application that demonstrates the approach from above.If you have any questions, please let me know.