I have a xamDataGrid which needs some custom UI controls overlaid on top of the grid. To that end, I have customized the template of the RecordListControl
<Style TargetType="{x:Type igDP:RecordListControl}" BasedOn="{StaticResource {x:Type igDP:RecordListControl}}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordListControl}"> <Border Background="{TemplateBinding Background}"> <Grid > <ScrollViewer CanContentScroll="true" Focusable="false" HorizontalScrollBarVisibility="{TemplateBinding HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding VerticalScrollBarVisibility}"> <my:CustomPanel> <my:CustomControl1/> <my:CustomControl2/> <my:CustomControl3/> <ItemsPresenter></ItemsPresenter> <!-- ItemsPresenter for the data grid -> </my:CustomPanel> </ScrollViewer> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> Then, I implemented the necessary Measure and Arrange logic in my CustomPanel to arrange the custom controls on top of the ItemsPresenter in the way that I need. This is actually working pretty well, except I am having a problem that seems to be virtualization-related. Inside the ItemsPresenter, I am seeing one DataRecordPresenter for each item in the XamDataGrid ItemsSource. However, most (beyond the first few) of the DataRecordPresenter have actual size = 0. This is happening despite having AllowCellVirtualization="false" and AllowLabelVirtualization="false" in my FieldSettings and RecordContainerGenerationMode="PreLoad", RecordLoadMode="PreloadRecords", CellContainerGenerationMode="PreLoad", ScrollingMode="Immediate" properties in the XamDataGrid.
So I have a few questions. 1) Is this the right overall design to accomplish what I need to do? 2) How can I get all the DataRecordPresenters to be realized with correct height and width? Is the fact that my custom panel is not a ScrollViewer related to the problem I am facing?
Hello Brian,
Thank you for your post. I have been looking into it and I created a sample project for you following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Looking forward for your reply.
Thanks Stefan. I am actually able to reproduce the issue using your demo project. If you increase the row count of your sample data from 100 to 1000, I am not able to scroll through 1000 rows as I would expect. The scroll viewer will only navigate through the first 50-100 rows. When I use a WPF Inspector like Snoop, I can see there are 1000 DataRecordPresenters generated in the visual tree, but beyond the first few dozen, the data record presenters all have ActualHeight and ActualWidth = 0.
Let me know if you are not seeing this issue on your end.
I was able to reproduce your behavior and I can say that this is the designed beahavior. If you give us more details why do you need the DataRecordPresenters to be preloaded and what is the result you want to achieve, I can try to think of a possible solution for you.
Hi stefen,
I set the data presenter pre loaded and check actual height 0 as what Brian did. I want the total height of grid.
In my case i am generating image of grid. But it takes only the visible area like first 10 or 15 DataRecordPresenters but not getting all Data Record.
because when i get Actual Height of Xmadatagrid it is just the visible area height.
here is my code what i used to generate BitmapSource
public static BitmapSource RenderToBitmap(FrameworkElement target) { Rect bounds = VisualTreeHelper.GetDescendantBounds(target); RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)target.ActualWidth, (int)target.ActualHeight, 96, 96, PixelFormats.Pbgra32);
DrawingVisual visual = new DrawingVisual(); using (DrawingContext context = visual.RenderOpen()) { VisualBrush brush = new VisualBrush(target); context.DrawRectangle(brush, null, new Rect(new Point(), bounds.Size)); }
renderBitmap.Render(visual);
return renderBitmap; }
i just call RenderToBitmap(grid) it return me image with viewable section. I want image of whole grid (all data record presenters).
Thanks
Adit
Hello Adit,
I can say that it is not possible to create an image of an elemnts that are currently not rendered and that are not in view, like the Records in the XDG.