Hi, I'm using XamDataGrid to display a bonds grouped by a bid list (see the image below). Sometimes I need to display bid lists that are empty (i.e. contain no bonds). To create an empty bid list grouping I insert a "special" fake bond into it. But in this case I want the grouping to show a special message spanning the columns (like the first groping in the image below). What is my best strategy to achieve something like this with XamDataGrid? Thanks!
Hello,
I am not sure how you are creating a dummy group, but I am adding an unique dummy item so that the XamDataGrids creates a group for it only. Then I am applying a custom template for that record (only if its parent is a GroupByRecord - i.e. is in a group). I have attached my sample, but here is some of the code that I am using :
27 xamDataGrid1.FieldLayoutSettings.DataRecordPresenterStyleSelector = new DRPStyleSelector(xamDataGrid1);
...
32 public class DRPStyleSelector : StyleSelector
33 {
34 private XamDataGrid _grid;
35 public DRPStyleSelector(XamDataGrid grid)
36 {
37 this._grid = grid;
38 }
39 public override Style SelectStyle(object item, DependencyObject container)
40 {
41 DataRecord dr = item as DataRecord;
42 Bid dataItem;
43 if (dr != null)
44 {
45 dataItem = dr.DataItem as Bid;
46 // a Bid with a negative Id is a dummy bid
47 if (dr.ParentRecord is GroupByRecord && dataItem != null && dataItem.Id < 0)
48 {
49 return _grid.Resources["DRPDummyStyle"] as Style;
50 }
51 }
52
53 return base.SelectStyle(item, container);
54 }
55 }
where DRPDummyStyle is a simple style for the data record presenter:
<Style TargetType="{x:Type igDP:DataRecordPresenter}" x:Key="DRPDummyStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:DataRecordPresenter}">
<Grid>
<TextBlock Text="Drag Bids here..." FontSize="16" Margin="10,10,10,20"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here is what I got :
Hi Alex, thanks a lot. This is very close to what I need. The one problem with your example I found is that when you collapse the "special" group and uncollapse it the style reverts to main one (with columns for every field). I'm using v9.2 of the XamDataGrid. Is there a workaround for that?
Hi Alex,
I changed you code to:public override Style SelectStyle(object item, DependencyObject container) { DataRecord dr = item as DataRecord; Bid dataItem;
dataItem = dr.DataItem as Bid; // a Bid with a negative Id is a dummy bid if (/*dr.ParentRecord is GroupByRecord && */ dataItem != null && dataItem.Id < 0) { return _grid.Resources["DRPDummyStyle"] as Style; }
return base.SelectStyle(item, container); }
and it made no difference. Just clicking on plus icon to close the group and then again to reopen restores the original template. Do you observe the same problem on you side?
I tried this and I cannot reproduce it ( I switched from 10.1 to the latest service release for 9.2 - 9.2.20092.2094 )
However I noticed a behavior when you are scrolling fast, the template for the dummy item could apply to a non-dummy item because of the virtualization. This can be resolved by switching to a more aggressive virtualization strategy - like Virtualize :
xamDataGrid1.RecordContainerGenerationMode = Infragistics.Windows.Controls.ItemContainerGenerationMode.Virtualize;
Please tell us what build of our controls are you using and what environment are you testing this agains (mine is 9.2.20092.2094, Windows 7 Enterprise).
Alex, I have switched to the latest service release (from 1007) and and I don't see the problem with closing/opening the group any more. I do see the problem with scrolling that you mentioned though. Switching to "Virtualize" slows down my real grid very significantly, so I would prefer to stay with default RecordContainerGenerationMode.Is there a different workaround for the scrolling problem?Another problem that I noticed relates to the fact that I have several columns in my grid fixed. When I scroll horizontally the "special" template is also scrolled away. Is there a way to "fix/pin" it?
Thanks!
There are couple of more ways to try with. If you cannot change the virtualization mode, then you can try with using only one style but changing only the ControlTemplate. For example - the DataRecordCellArea. Here is an example of what I have in mind :
<Style TargetType="{x:Type igDP:DataRecordCellArea}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DataItem.Id}" Value="-1">
<ControlTemplate TargetType="{x:Type igDP:DataRecordCellArea}">
<TextBlock Text="Drag Bids here..." FontSize="16" Margin="10,10,10,20" />
</DataTrigger>
</Style.Triggers>
However, going with this, it would be hard to keep the TextBlock from not scrolling. You would have a better control over its position if you retemplate the CellValuePresenter element instead. You could create a dummy unbound field and put it "under" the pinned fields. Here is a sample style for the CellValuePresenter:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Grid Background="Transparent">
<TextBlock Text="Drag Bids here..." FontSize="16" x:Name="tblock"
Visibility="{Binding Path=Field.Name, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource conv}}"/>
The converter is used to return Visible only if the Field.Name matches the name of the Dummy Unbound Field. Here is a screenshot of what I am getting and the full sample:
I was just wondering if that solution works on your end? Please let me know if you have questions on this matter.