tags:

views:

55

answers:

2

Hi - I'm trying to use David Poll's printcollection control, from the SLaB project- www.davidpoll.com but for some reason no items get shown. Maybe it's something with my itemtemplate, please have a look at this:

 <Style x:Key="PrintStyle"
    TargetType="SLaB:CollectionPrinter">
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                        <Grid>
                        <sdk:Label x:Name="lblTitle" HorizontalAlignment="Left" Margin="0,8,0,0" VerticalAlignment="Top" Content="{Binding Source={StaticResource ResourceWrapper}, Path=NoteEditorResources.Title}"/>
                        <sdk:Label x:Name="lblTitleResult" HorizontalAlignment="Left" Margin="42,8,0,0" VerticalAlignment="Top" Content="{Binding Path=Title}"/>
                        <sdk:Label x:Name="lblDateCreated" HorizontalAlignment="Right" Margin="0,8,156,0" VerticalAlignment="Top" Content="{Binding Source={StaticResource ResourceWrapper}, Path=NoteEditorResources.DateCreated}"/>
                        <sdk:Label x:Name="lblDateCreatedResult" HorizontalAlignment="Right" Margin="0,8,113,0" VerticalAlignment="Top" Content="{Binding Path=DateCreated}"/>
                        <RichTextBox x:Name="rtbContent" Margin="0,28,0,8" Width="582" Xaml="{Binding Content}" />
                        </Grid>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                <StackPanel HorizontalAlignment="Stretch">
                    <StackPanel HorizontalAlignment="Right"
                    Orientation="Horizontal">
                        <TextBlock Text="{Binding CurrentPage, StringFormat='{}Page {0} '}" />
                        <TextBlock Text="{Binding PageCount, StringFormat='{}/ {0}'}" />
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="FooterTemplate">
            <Setter.Value>
                 <DataTemplate>
                <StackPanel HorizontalAlignment="Center"
                Orientation="Horizontal">
                    <TextBlock Text="{Binding FirstItemValue.Name}" />
                    <TextBlock Text=" - " />
                    <TextBlock Text="{Binding LastItemValue.Name}" />
                </StackPanel>
            </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
A: 

I've used his printing control, but I never modified the itemtemplate. I used his TestPrinter.xaml as a template and filled in the HeaderTemplate, FooterTemplate, and the BodyTemplate with my code.

The BodyTemplate being the important one to take a look at. Here is the BodyTemplate section from his example:

<Printing:CollectionPrinter.BodyTemplate>
    <DataTemplate>
        <sdk:DataGrid ItemsSource="{Binding CurrentItems}"
                      AutoGenerateColumns="False"
                      VerticalScrollBarVisibility="Disabled">
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Name}"
                                        Header="Name" />
                <sdk:DataGridTextColumn Binding="{Binding Address}"
                                        Header="Address" />
                <sdk:DataGridTextColumn Binding="{Binding Age}"
                                        Header="Age" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
    </DataTemplate>
</Printing:CollectionPrinter.BodyTemplate>

The important thing is to set the CurrentItems as the source for your control that will be used to display your collection. This way it can automatically calculate how many items to display in the page before they cut off.

Fama