How to print each object in a collection in a separate page in Silverlight
Posted
by
Ash
on Stack Overflow
See other posts from Stack Overflow
or by Ash
Published on 2014-08-22T16:16:14Z
Indexed on
2014/08/22
16:19 UTC
Read the original article
Hit count: 231
I would like to know if its possible to print each object in a collection in separate pages using Silverlight printing API.
Suppose I have a class Label
public class Label
{
public string Address { get; set; }
public string Country { get; set; }
public string Name { get; set; }
public string Town { get; set; }
}
I can use print API and print like this.
private PrintDocument pd;
private void PrintButton_Click(object sender, RoutedEventArgs e)
{
pd.Print("Test Print");
}
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Label labelToPrint = new Label()
{
Name = "Fake Name", Address = "Fake Address",
Country = "Fake Country", Town = "Town"
};
var printpage = new LabelPrint();
printpage.DataContext = new LabelPrintViewModel(labelToPrint);
e.PageVisual = printpage;
}
LabelPrint Xaml
<StackPanel x:Name="LayoutRoot" VerticalAlignment="Center"
HorizontalAlignment="Center">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Address}" />
<TextBlock Text="{Binding Town}" />
<TextBlock Text="{Binding Country}" />
</StackPanel>
Now, say I've a collection of Label objects,
List<Label> labels = new List<Label>()
{
labelToPrint, labelToPrint, labelToPrint, labelToPrint
};
How can I print each object in the list in separate pages ?
Thanks for any suggestions ..
© Stack Overflow or respective owner