简体   繁体   English

Fixeddocument中Itemscontrol内的分页符

[英]Pagebreak inside Itemscontrol in Fixeddocument

In my Application, I have the need for generating different reports. 在我的应用程序中,我需要生成不同的报告。 Most of them fit on a single page. 它们大多数都放在一个页面上。 I created those reports with FixedDocuments. 我使用FixedDocuments创建了这些报告。 Now I try to create some kind of letter in a FixedDocument. 现在,我尝试在FixedDocument中创建某种字母。 It contains among other things a header, a complimentary close and a subject. 它除其他外还包含标题,免费关闭和主题。 These parts work without any problems. 这些部件可以正常工作。 They are all separated into UserControls. 它们都被分成UserControls。

The main content of the letter gives me some headache. 这封信的主要内容使我有些头疼。 This should be a nested ItemsControl bound to a custom list (categoryList). 这应该是绑定到自定义列表(categoryList)的嵌套ItemsControl。 Each item of the custom list consists of a string (category) and another list (valueList). 自定义列表的每个项目都由一个字符串(类别)和另一个列表(valueList)组成。 The elements of the other list consist of two strings (caption, value). 另一个列表的元素由两个字符串(标题,值)组成。 The ItemsControl looks like this: ItemsControl看起来像这样:

<ItemsControl ItemsSource="{Binding categoryList}"
              DockPanel.Dock="Top"
          Margin="20,10,0,0">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" Margin="0" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding category}"/>
                <ItemsControl ItemsSource="{Binding valueList}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" Margin="0" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding caption}"
                                                       Grid.Column="0" />
                                <TextBlock Text="{Binding value}"
                                                       Grid.Column="1" />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

If the categoryList and the valueList both contain only a few elements, everything works fine. 如果categoryList和valueList都只包含几个元素,则一切正常。 But with a certain amount of elements, the ItemsControl gets clipped. 但是,有了一定数量的元素,ItemsControl将被裁剪。

This is how I create the FixedDocument via code: 这就是我通过代码创建FixedDocument的方式:

FixedDocument doc = new FixedDocument();

FixedPage page = new FixedPage();
PageContent page1= new PageContent();

//All UserControls are placed inside a DockPanel
DockPanel panel = new DockPanel();

//UserControl with header
Header header = new Header();
DockPanel.SetDock(header, Dock.Top);
panel.Children.Add(header);

//UserControl with complimentary close
Complimentary complimentary = new Complimentary();
DockPanel.SetDock(complimentary, Dock.Top);
panel.Children.Add(complimentary);

//UserControl with subject
Subject subject = new Subject();
DockPanel.SetDock(subject , Dock.Top);
panel.Children.Add(subject);

//UserControl with ItemsControl for categoryList
Categories categories = new Categories();
DockPanel.SetDock(categories,Dock.Top);
panel.Children.Add(categories);

//Add the DockPanel to the page
page.Children.Add(panel);

//Set the PageContent
page1.Child = page;
doc.Pages.Add(page1);
//Set the DataContext for the Binding
doc.DataContext = this.listWithValues;
//Display the result in a DocumentReader
this.reader.Document = doc;

Is there a way to place a page break inside of the ItemsControl? 有没有一种方法可以在ItemsControl中放置分页符? Either before the first category that will cause the overflow. 在第一个类别之前,这将导致溢出。 Or even better inside the category that will cause the overflow. 甚至在类别内更好,这将导致溢出。

Thanks for any suggestion and advice! 感谢您的任何建议和意见! If any other information is needed, feel free to ask. 如果需要其他信息,请随时询问。

I've been looking into the FixedDocument myself as a solution to enable copying from a statistics display. 我一直在寻找FixedDocument作为解决方案,以实现从统计显示中进行复制。

The FixedDocument class is, by definition, WYSIWYG, meaning that the content on each page is explicitly defined; 根据定义,FixedDocument类是WYSIWYG,意味着每个页面上的内容都已明确定义; you define precisely which content you want on a page and then add that PageContent to the FixedDocument. 您可以精确定义要在页面上显示的内容,然后将该PageContent添加到FixedDocument。 By design, content will not flow from page to page. 根据设计,内容不会在页面之间流动。

Since, as you say, your categories are "overflowing," you were already on the way to the solution...you want to use a FlowDocument instead of a FixedDocument. 就像您说的那样,由于类别正在“溢出”,因此您已经在寻求解决方案...您想使用FlowDocument而不是FixedDocument。 A FlowDocument will flow your content based on the content itself, as well as the font size and other context. FlowDocument将根据内容本身以及字体大小和其他上下文来流转您的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM