ItemsControl:如何在多个页面上打印WrapPanel?

发布于 2024-11-08 21:03:32 字数 2754 浏览 0 评论 0原文

我正在尝试打印此内容,但只出现第一页。 例如,如果 ItemsControlCodigos 有 200 个项目,则仅显示 1 页。

这怎么能轻易做到呢?

<FlowDocumentReader Name="FlowDocumentReader1" Margin="397,85,0,0">
        <FlowDocument Name="fd">
            <BlockUIContainer>
                <ItemsControl Name="ItemsControlCodigos" >
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel IsItemsHost="True"  />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock FontFamily="Tahoma" FontSize="10pt" Text="{Binding Descricao, TargetNullValue='--'}" Width="100px" />
                                <StackPanel Orientation="Horizontal" Width="100px">
                                    <TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="(" />
                                    <TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="{Binding id_Produto}" />
                                    <TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text=")" />
                                </StackPanel>
                                <Button Name="buttonExcluirItem" BorderThickness="0" BorderBrush="Transparent" Background="Transparent" 
                                    VerticalAlignment="Center"
                                    Margin="-4,-1,-1,-1"

                                    Opacity="0.3"
                                    ToolTip="Excluir este Item">
                                    <Image Width="16" Height="16"  />
                                </Button>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

            </BlockUIContainer>
        </FlowDocument>
    </FlowDocumentReader>

C#

private void ButtonImprimir_Click(object sender, RoutedEventArgs e)
{

    // 20-05-2011
    PrintDialog pd = new PrintDialog();

    //pd.PrintVisual(ItemsControlCodigos, "Etiquetas");
    fd.PageHeight = pd.PrintableAreaHeight; 
    fd.PageWidth = pd.PrintableAreaWidth; 
    fd.PagePadding = new Thickness(50); 
    fd.ColumnGap = 0; 
    fd.ColumnWidth = pd.PrintableAreaWidth; 

    IDocumentPaginatorSource dps = fd;
    //dps.DocumentPaginator.PageCount;
    pd.PrintDocument(dps.DocumentPaginator, "flow doc"); 

}

I am trying to print this, but only the first page appears.
for example if ItemsControlCodigos has 200 items, only 1 page appears.

How can this be done easily?

<FlowDocumentReader Name="FlowDocumentReader1" Margin="397,85,0,0">
        <FlowDocument Name="fd">
            <BlockUIContainer>
                <ItemsControl Name="ItemsControlCodigos" >
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel IsItemsHost="True"  />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock FontFamily="Tahoma" FontSize="10pt" Text="{Binding Descricao, TargetNullValue='--'}" Width="100px" />
                                <StackPanel Orientation="Horizontal" Width="100px">
                                    <TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="(" />
                                    <TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="{Binding id_Produto}" />
                                    <TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text=")" />
                                </StackPanel>
                                <Button Name="buttonExcluirItem" BorderThickness="0" BorderBrush="Transparent" Background="Transparent" 
                                    VerticalAlignment="Center"
                                    Margin="-4,-1,-1,-1"

                                    Opacity="0.3"
                                    ToolTip="Excluir este Item">
                                    <Image Width="16" Height="16"  />
                                </Button>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

            </BlockUIContainer>
        </FlowDocument>
    </FlowDocumentReader>

C#

private void ButtonImprimir_Click(object sender, RoutedEventArgs e)
{

    // 20-05-2011
    PrintDialog pd = new PrintDialog();

    //pd.PrintVisual(ItemsControlCodigos, "Etiquetas");
    fd.PageHeight = pd.PrintableAreaHeight; 
    fd.PageWidth = pd.PrintableAreaWidth; 
    fd.PagePadding = new Thickness(50); 
    fd.ColumnGap = 0; 
    fd.ColumnWidth = pd.PrintableAreaWidth; 

    IDocumentPaginatorSource dps = fd;
    //dps.DocumentPaginator.PageCount;
    pd.PrintDocument(dps.DocumentPaginator, "flow doc"); 

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-11-15 21:03:32

这里的问题是 FlowDocumentDocumentPaginator 不会对 BlockUIContainer 进行分页,即它不会破坏 BlockUIContainer 内容跨多个页面。我在这里回答了类似的问题 在多个页面上打印 flowdocument 滚动查看器

简而言之,您必须创建多个 BlockUIContainer,每个 BlockUIContainer 都包含其 itemsControl。

或者本文中解释了一种打印整个控件(视觉)的非正统方法 http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls

其中控件被转换为位图,然后根据到要打印的页面大小。

谢谢

The issue here is that the DocumentPaginator of FlowDocument does not paginate the BlockUIContainer i.e it does not break the BlockUIContainer content across multiple pages. I have answered the similar question here Print flowdocument scroll viewer on multiple pages

In short, you will have to create multiple BlockUIContainer each containing its itemsControl.

OR There is an unorthodox way of printing the whole Control(Visual) explained in this article http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls

where control was converted to Bitmap which was then chopped according to the pagesize to print.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文