如何在silverlight中打印多个页面。 实际上我有一个Silverlight的场景,我有按钮点击事件,我可以打印单页中的所有内容,所有多余的内容已被删除但我没有得到下一页打印
这是我的按钮点击事件
private void btnSubmitPrint_Click(object sender, RoutedEventArgs e)
{
_currentIndex = 0;
PrintDocument docprin = new PrintDocument();
docprin.PrintPage += new EventHandler<PrintPageEventArgs>(docprin_PrintPage);
string DocumentName = "Balaji";
docprin.Print(DocumentName);
}
//I Combine all the List into to a single string by using Linq
void docprin_PrintPage(object sender, PrintPageEventArgs e)
{
string delimeter = "\n";
var checkval = ListOfPageComments.Select(i => i.Comment.Insert(100, Environment.NewLine));//This lINQ OPERATION
var ListofPagecommentsAscending = from n in ListOfPageComments orderby n.Date descending select n;
var CommentsLineBreaks = ListofPagecommentsAscending.Select(conmmentss =>
{
var retur = conmmentss;
if (conmmentss.Comment.Length > 100)
{
IEnumerable<string> spllitingvaluetoNewLine = (Enumerable.Range(0, conmmentss.Comment.Length / 100).Select(j => conmmentss.Comment.Substring(j * 100, 100)));
string RejoiningLinestoSingle = String.Join(" \n ", spllitingvaluetoNewLine);
conmmentss.Comment = RejoiningLinestoSingle;
return conmmentss;
}
return conmmentss;
});
var delimitedcomments = CommentsLineBreaks.Select(i => i.Date + "\n" + i.Comment).Aggregate((i, j) => i + delimeter + j);
string Printcomments = String.Join(delimeter, delimitedcomments);
List<string> get = (Enumerable.Range(0, Printcomments.Length / 800).Select(j => Printcomments.Substring(j * 800, 800))).ToList();
//AFTER GETTING THE VALUE OF STRING I SPLIT THEM INTO A LIST
while (_currentIndex < get.Count())//lOOPING CONDITION TO PRINT MULTIPLE PAGES
{
var pageRoot = new Canvas();
e.PageVisual = pageRoot;
_currentTop = PAGEMARGIN;
_availableSpace = e.PrintableArea.Height - PAGEMARGIN * 2;
// var txt = new TextBlock { Text = Printcomments };
var txt = new TextBlock { Text = get[_currentIndex].ToString() };
if (ROWHEIGHT > _availableSpace)
{
e.HasMorePages = true;
break;
}
txt.SetValue(Canvas.TopProperty, _currentTop);
txt.SetValue(Canvas.LeftProperty, PAGEMARGIN);
_currentTop += ROWHEIGHT;
_availableSpace -= ROWHEIGHT;
pageRoot.Children.Add(txt);
_currentIndex++;
}
}