This question is locked. New answers and comments are not allowed.
Hello ,
I try to add custom header and footer in a radDocument, but when I do , i can only write a single page . When going to the second page the editor disappears here's the function i'd like to use
The exeption is
:
Thank you for your attention.
Mathieu
I try to add custom header and footer in a radDocument, but when I do , i can only write a single page . When going to the second page the editor disappears here's the function i'd like to use
public void InsertPageLayout() { Section section = this.RichTextBox.Document.Sections.First; section.HasDifferentFirstPageHeaderFooter = false; this.RichTextBox.Document.HasDifferentEvenAndOddHeadersFooters = false; RadDocument footerBody = new RadDocument(); footerBody.LineSpacing = 1.15; footerBody.ParagraphDefaultSpacingBefore = 5; footerBody.ParagraphDefaultSpacingAfter = 5; footerBody.SectionDefaultPageMargin = new Padding(95); Section sectionF = new Section(); Paragraph p = new Paragraph(); Span s = new Span(); s.Text = "Footer"; p.Inlines.Add(s); sectionF.Blocks.Add(p); RadDocument headerBody = new RadDocument(); headerBody.LineSpacing = 1.15; headerBody.ParagraphDefaultSpacingBefore = 5; headerBody.ParagraphDefaultSpacingAfter = 5; headerBody.SectionDefaultPageMargin = new Padding(95); Section sectionH = new Section(); Paragraph ph = new Paragraph(); //ph.LeftIndent = 0; ImageInline im = new ImageInline(this.GetResourceUri("images/Lighthouse.jpg")); /*if (im.UriSource == null { BitmapImage imSource = new BitmapImage(); }*/ double pixelHeight = im.ImageSource.PixelHeight; double pixelWidth = im.ImageSource.PixelWidth; double proportion = pixelHeight / pixelWidth; bool portrait = true; double largeur; if (portrait) { largeur = 21 / 0.0264; } else { largeur = 29.7 / 0.0264; } double margeHaut = 1; double margeBas = 1; double margeGauche = 1 / 0.0264; double margeDroite = 12 / 0.0264; double largeurImg = largeur - (margeGauche + margeDroite); double hauteurImg = largeurImg * proportion; // Convertir cm en unité px im.Width = largeurImg; im.Height = hauteurImg; Span sh = new Span(); sh.Text = "Header"; //ph.Inlines.Add(im); ph.Inlines.Add(sh); sectionH.Blocks.Add(ph); //sectionH.ActualPageMargin = new Padding(0, 0, 0, 0); headerBody.Sections.Add(sectionH); footerBody.Sections.Add(sectionF); Header header = new Header() { Body = headerBody, IsLinkedToPrevious = false }; Footer footer = new Footer() { Body = footerBody, IsLinkedToPrevious = false }; //document is an instance of RadDocument, representing the content of the footer, //document is an instance of RadDocument, representing the content of a Header, //typically contains a few paragraphs //section.Headers.First = header; //section.Footers.First = footer; //header.Body.InsertReadOnlyRange(startPosition:new DocumentPosition(headerBody), endPosition:new DocumentPosition(headerBody)); //footer.Body.InsertReadOnlyRange(startPosition: new DocumentPosition(footerBody), endPosition: new DocumentPosition(footerBody)); RadDocument footerBody2 = new RadDocument(); Section sectionF2 = new Section(); Paragraph pf2 = new Paragraph(); Span sf2 = new Span(); sf2.Text = "Footer 2"; pf2.Inlines.Add(sf2); sectionF2.Blocks.Add(pf2); RadDocument headerBody2 = new RadDocument(); Section sectionH2 = new Section(); Paragraph ph2 = new Paragraph(); //ph2.Inlines.Add(im); Span sh2 = new Span(); sh2.Text = "Header 2"; ph2.Inlines.Add(sh2); sectionH2.Blocks.Add(ph2); headerBody2.Sections.Add(sectionH2); Header header2 = new Header() { Body = headerBody2, IsLinkedToPrevious = true }; Footer footer2 = new Footer() { Body = footerBody2, IsLinkedToPrevious = true }; //Section section2 = new Section(); //section2.Blocks.Add(new Paragraph()); //section.Headers.Even = header2; //section.Footers.Even = footer2; //section.Headers.Default = header; //section.Footers.Default = footer; this.RichTextBox.UpdateFooter(section, HeaderFooterType.Default, footer); this.RichTextBox.UpdateHeader(section, HeaderFooterType.Default, header); this.InsertPageLayoutResponseComplete(this, null); }public event DownloadStringCompletedEventHandler InsertPageLayoutResponseComplete; private void OnInsertPageLayoutResponseComplete(object sender, DownloadStringCompletedEventArgs e) { if (InsertPageLayoutResponseComplete != null) { InsertPageLayoutResponseComplete(this, e); } }The exeption is
Uncaught Error: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet. à Telerik.Windows.Documents.Model.RadDocument.get_ParagraphDefaultSpacingBefore() à Telerik.Windows.Documents.Model.RadDocument.CopyPropertiesFromOverride(DocumentElement element) à Telerik.Windows.Documents.Model.DocumentElement.CopyPropertiesFrom(DocumentElement fromElement) à Telerik.Windows.Documents.Model.DocumentElement.CreateElementCopy() à Telerik.Windows.Documents.Model.DocumentElement.CreateShallowCopy(DocumentElement documentElement) à Telerik.Windows.Documents.Model.DocumentElement.CreateShallowCopy() à Telerik.Windows.Documents.Model.DocumentElement.CreateDeepCopy(DocumentElement root) à Telerik.Windows.Documents.Model.DocumentElement.CreateDeepCopy() à Telerik.Windows.Documents.Model.RadDocument.CreateDeepCopy(Boolean copyStyles) à Telerik.Windows.Documents.UI.HeaderPresenter.GetBody() à Telerik.Windows.Documents.UI.HeaderFooterPresenterBase.UpdateBody() à Telerik.Windows.Documents.UI.HeaderFooterPresenterBase.OnApplyTemplate() à System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)Thank you for your attention.
Mathieu