Bound Grids -- not creating the right DesiredSize: Fail to page properly

Jan 9, 2012 at 7:17 PM
Edited Jan 9, 2012 at 8:29 PM

I am building a fairly sophisticated (but not wildly so) report that has a variable number of rows and columns.

Unfortunately, as I walk through the "BuildReport" method, the DesiredSize of each row of information (which is bound to a datagrid) comes out at a measly 64 pixels (vs the 28 or so lines of data I have bound to it.

Is there a way to get the actual size sooner, so that the size is properly estimated and we trip teh "next page" concerpt.

Is this implementation such that any "unknown" binding size will not work ?

 

Here is my XAML for the report template:

 

     
     <!--Item template -->
                <reporting:Report.ItemTemplate>
                    <DataTemplate>
                        <!-- The Grid -->
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="34" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Grid   Grid.Row="0"
                                HorizontalAlignment="Stretch">

                                <TextBlock  Margin="1,1,1,2" HorizontalAlignment="Center"
                                        Text="{Binding Path=Header}" Style="{StaticResource TitleTextStyle}" 
                                      />

                            </Grid>
                            <sdk:DataGrid  Grid.Row="1" 
                                x:Name="OQGrid" AutoGenerateColumns="False" ItemsSource="{Binding QualRows}">
                            <sdk:DataGrid.Columns>
                                <sdk:DataGridTextColumn Binding="{Binding QualificationCode}"  Header="Code"/>
                                <sdk:DataGridTextColumn Binding="{Binding QualificationName}"  Header="Name"/>
                                
                                <sdk:DataGridTemplateColumn Width="*">
                                    <sdk:DataGridTemplateColumn.HeaderStyle>
                                        <Style TargetType="primitives:DataGridColumnHeader">
                                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                            <Setter Property="VerticalContentAlignment"  Value="Stretch" />
                                            <Setter Property="Margin" Value="0" />
                                            <Setter Property="ContentTemplate">
                                                <Setter.Value>
                                                    <DataTemplate>
                                                        <ItemsControl  ItemsSource="{Binding DataContext.WorkerNames, ElementName=OQGrid}">
                                                            <ItemsControl.ItemsPanel>
                                                                <ItemsPanelTemplate>
                                                                    <StackPanel Orientation="Horizontal">
                                                                    </StackPanel>
                                                                </ItemsPanelTemplate>
                                                            </ItemsControl.ItemsPanel>
                                                            <ItemsControl.ItemTemplate>
                                                                <DataTemplate>
                                                                    <Border  Width="70" >
                                                                        <TextBlock Text="{Binding}"  TextWrapping="Wrap" Margin="2"
                                                                                   TextAlignment="Center"/>
                                                                    </Border>
                                                                </DataTemplate>
                                                            </ItemsControl.ItemTemplate>
                                                        </ItemsControl>
                                                    </DataTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </sdk:DataGridTemplateColumn.HeaderStyle>
                                    <sdk:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <ItemsControl  ItemsSource="{Binding WorkerQualified}">
                                                <ItemsControl.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <StackPanel Orientation="Horizontal"/>
                                                    </ItemsPanelTemplate>
                                                </ItemsControl.ItemsPanel>
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Border Width="70">
                                                            <CheckBox IsChecked="{Binding}"  HorizontalAlignment="Center"/>
                                                        </Border>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </DataTemplate>
                                    </sdk:DataGridTemplateColumn.CellTemplate>
                                </sdk:DataGridTemplateColumn>
                            </sdk:DataGrid.Columns>
                        </sdk:DataGrid>
                        </Grid>
                          

                    </DataTemplate>
                </reporting:Report.ItemTemplate>
Coordinator
Jan 9, 2012 at 8:36 PM

Is there a specific reason you're using a DataGrid for this? The DataGrid is a pretty heavy control meant for interactivity.

I haven't tested the report with datagrids. Although there has been a request to be able to build a report based on one, using the grid itself for report display is not on my list.

Also, it looks like you're creating a separate datagrid for each row in the report. I'm not sure how big the report will be, but that could be a LOT of datagrids. Memory for the app would likely go a bit nuts.

Pete

Jan 9, 2012 at 8:40 PM

Datagrid was easy because it was bound.  This construct created the columns (up to 8) and rows (up to 30) .. so it really doesn't get that big.

Anyway, I modified the approach by creating an interface for the datacontext called "Clues", and put SuggestedHeight on the context if I feel it can't figure it out.

Also -- would be useful to do a scale transform if a single object could not fit.

 

I like your basic approach !

 

--mike