Hello,
I have implemented a cell merging in my XamDataGrid. I overrode the default Infragistics template to provide functionality that adds custom border if there is a property "DropTargetType" in the underlying row equal to custom enum "DropTargetType.Regular".
BUT, there is strange behavior I don't know how to deal with: the merged cell style's DataContext is set to the last of merged rows. How can I change this DataContext to the first merged row?
There is a simple code I use. It works correctly if the property in the last of merged rows "DropTargetType" is equal to "DropTargetType.Regular". However, I would like it to be dependent on the first merged row.
<Style TargetType="{x:Type igDP:MergedCellPresenter}" x:Key="DefaultMergedCellPresenter"> <Setter Property="Background" Value="{DynamicResource {x:Static igDP:DataPresenterBrushKeys.MergedCellBackgroundKey}}"/> <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}"/> <Setter Property="BorderThickness" Value="0 0 1 1"/> <!--Econosim change--> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:MergedCellPresenter}"> <!--change start--> <Border x:Name="DropTargetBorder" BorderThickness="0 0 0 0" BorderBrush="Black"> <!--change end--> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" > <igDP:CellValuePresenter x:Name="PART_CellValuePresenter" Field="{TemplateBinding Field}" Value="{TemplateBinding Value}" BorderThickness="0" IsMergedCell="True"/> </Border> </Border> <ControlTemplate.Triggers> <!--change start--> <DataTrigger Binding="{Binding DataItem.DropTargetType}" Value="{x:Static utils:DropTargetType.Regular}"> <Setter Property="BorderThickness" Value="0 1 0 0" TargetName="DropTargetBorder"/> </DataTrigger> <!--change end--> <Trigger Property="IsOpacityReduced" Value="True"> <Setter TargetName="PART_CellValuePresenter" Property="Opacity" Value="0.35"/> </Trigger> <Trigger Property="IsFieldSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource {x:Static igDP:DataPresenterBrushKeys.MergedCellFieldSelectedBackgroundKey}}"/> <Setter Property="BorderBrush" Value="{DynamicResource {x:Static igDP:DataPresenterBrushKeys.MergedCellFieldSelectedBorderBrushKey}}"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsFixed" Value="True"/> <Condition Property="IsRecordSelected" Value="False"/> <Condition Property="IsSelected" Value="False"/> <Condition Property="IsFieldSelected" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="{DynamicResource {x:Static igDP:DataPresenterBrushKeys.MergedCellFieldFixedBackgroundKey}}"/> <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}"/> </MultiTrigger> <Trigger Property="IsRecordSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource {x:Static igDP:DataPresenterBrushKeys.MergedCellRecordSelectedBackgroundKey}}"/> <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource {x:Static igDP:DataPresenterBrushKeys.MergedCellSelectedBackgroundKey}}"/> <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Best regards,
Mateusz
Thank you, this solution helped me. I also added trigger to CellValuePresenter so that it doesn't show line if it is merged cell - responsible for this is a piece of code from you added to MergedCellPresenter. This resolved my problem.
<MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding DataItem.ShowLine}" Value="True"/> <Condition Binding="{Binding IsMergedCell, RelativeSource={RelativeSource Self}}" Value="False"/> </MultiDataTrigger.Conditions> <Setter Property="BorderThickness" Value="0 1 0 0" TargetName="DropTargetBorder"/> </MultiDataTrigger>
Try updating your trigger in your mergedcellpresenter.
eg.
<ControlTemplate.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataRecords[0].DataItem.ShowLine}" Value="True"> <Setter Property="BorderThickness" Value="0 1 0 0" TargetName="DropTargetBorder"/> </DataTrigger> </ControlTemplate.Triggers>
I have checked your attached project and, to be honest, I don't see any difference in behavior to the previous state without merged cell style. I mean, the style of a merged cell still depends on the second of the merged rows instead of the first one. I have simplified a little bit your last project to focus only on merged cell - I removed border over normal cells.
If you confirm that there is nothing I can do to make the red border to be only above "Smith" instead of "Santana" then I will give up on this idea in my program.
Project: https://easyupload.io/8193e3
Hello Mateusz,
Thank you for following up. I reviewed your sample and noticed it's only using a CellValuePresenter style. You are going to need a combination of both a CellValuePresenter style and MergedCellPresenter style (see attached). However merged cells still have cellvaluepresenters next to them which makes it difficult to achieve this requirement for when clicking the cells. I would try and keep it simple. Styling merged cells is alone is easily achievable but doing so with the row in mind is considered to be a new product idea.XamDataGridMergedRowStyleDemo.zip
Maybe this link: https://easyupload.io/60lyzt
easyupload.io/60lyzt
Best regards