Hi Every Body…
I use RadRichTextBox control, and my requirement is to add border to every page in the document, like that shown in the attached image.
As RadRichTextBox control doesn't support adding shapes, I tried using DecorationUILayerBase, but unfortunately I couldn't use it with the headers (to achieve my requirement).
So I tried another technique utilizing InlineUiContaineers, where I created the required structure (including the require border) and added them to a Grid control, then adding that Grid to an instance of InlineUIContainer class, and adding that instance to the header section of an instance of RadDocument class, and finally setting that instance to the Document property of my RadRichTextBox control.
This solution worked for
the header of the first page only, but as the user continues writing and
reaching end of this first page and new page is added the following error is
thrown:
"Specified element is already the logical child of another element.
Disconnect it first."
My code snippet is as the following:
Me.radRichTextBox.Document
= CreateDocumentWithCustomHeader()
Public Function CreateDocumentWithCustomHeader() As RadDocument
Dim doc As New RadDocument()
doc.LayoutMode = DocumentLayoutMode.Paged
Dim headerDoc As New RadDocument()
Dim hSection As New Section()
headerDoc.Sections.Add(hSection)
headerDoc.SectionDefaultPageMargin = New Telerik.Windows.Documents.Layout.Padding(5,
5, 5, 5)
Dim hparagraph As New Paragraph()
hSection.Blocks.Add(hparagraph)
Dim grid As New Grid
Dim column1 As New ColumnDefinitionWith {.Width = NewGridLength(150)}
Dim column2 As New ColumnDefinitionWith {.Width = NewGridLength(0, GridUnitType.Star)}
Dim column3 As New ColumnDefinitionWith {.Width = NewGridLength(150)}
grid.ColumnDefinitions.Add(column1)
grid.ColumnDefinitions.Add(column2)
grid.ColumnDefinitions.Add(column3)
Dim MinistryImage As New Image
MinistryImage.Source = BitmapManager.CreateBitmapImage("pack://application:,,,/Images/ Logo1.png",
150)
Dim LogoImage As New Image
LogoImage.Source = BitmapManager.CreateBitmapImage("pack://application:,,,/Images/Logo2.png",
150)
grid.SetColumn(LogoImage, 0)
grid.SetRow(LogoImage, 0)
grid.SetColumn(MinistryImage, 2)
grid.SetRow(MinistryImage, 0)
grid.Children.Add(LogoImage)
grid.Children.Add(MinistryImage)
Dim border As New Controls.BorderWith {.BorderThickness = New Thickness(4),
.CornerRadius = New CornerRadius(5),
.BorderBrush = New SolidColorBrush(Colors.Black)}
grid.SetColumn(border, 0)
grid.SetRow(border,
0)
grid.SetColumnSpan(border, 3)
grid.Children.Add(border)
border.HorizontalAlignment = Windows.HorizontalAlignment.Stretch
border.VerticalAlignment = Windows.VerticalAlignment.Stretch
border.Margin = New Thickness(5,
5, 5, -500)
grid.HorizontalAlignment = Windows.HorizontalAlignment.Stretch
grid.VerticalAlignment = Windows.VerticalAlignment.Stretch
Dim container As New InlineUIContainer()
container.UiElement
= grid
container.Height =
150
container.Width =
700
hparagraph.Inlines.Add(container)
Dim header As New Header()
header.Body =
headerDoc
Dim section As New Section()
section.Headers.Default = header
doc.Sections.Add(section)
doc.SectionDefaultPageMargin = New Telerik.Windows.Documents.Layout.Padding(10, 10, 10, 10)
Return doc
End Function