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. Now I try to create some kind of letter in a 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.
The main content of the letter gives me some headache. This should be a nested ItemsControl bound to a custom list (categoryList). Each item of the custom list consists of a string (category) and another list (valueList). The elements of the other list consist of two strings (caption, value). The ItemsControl looks like this:
<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. But with a certain amount of elements, the ItemsControl gets clipped.
This is how I create the FixedDocument via code:
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? 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.