This is a migrated thread and some comments may be shown as answers.

Insert Footnote programmatically

7 Answers 119 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Daniela
Top achievements
Rank 1
Daniela asked on 26 Nov 2012, 08:57 AM
Hi!

I'm looking for a way to insert a footnote at a specific point in my RadRichTextbox programmatically.

The text of the footnote is stored in my data for a specific Span and should be inserted after the Text in the Span.

I know that the instance of the RadRichTextbox has the method InsertFootnote() or InsertFootnote(Note note) but I can not see
a) howthe position of the footnote is determined (does the 'cursor' of the radRichTextBox stand at the position where the last element was inserted?)
b) howthe text of the footnote can be set.

Can anyone provide a short example how I can insert a footnote at the end of a text, which is positioned in a span? I'm using Silverlight 5 and telerik version Q3 2012. I prepared a code of a code behind file of the MainPage at line 44 I wanted to insert the footnote. Maybe this expample helps to understand my problem and to provide an example for me:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Documents.Model;
 
namespace FootnoteExample
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
 
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            RadDocument document = new RadDocument();
 
            document.LayoutMode = DocumentLayoutMode.Paged;
 
            Section section = new Section();
 
            Table whatEverTable = new Table();
             
            TableRow row = new TableRow();
 
 
            TableCell cell = new TableCell();
            cell.Padding = new Telerik.Windows.Documents.Layout.Padding(0);
            cell.Padding = new Telerik.Windows.Documents.Layout.Padding(0);
            Paragraph p2 = new Paragraph();
            p2.LineSpacing = 1;
            
            Span s2 = new Span();
            s2.Text = "This is my text";
                string footnotetext = "My footnote text!";
            //  footnote should be inserted directly after this text
            p2.Children.Add(s2);
            cell.Blocks.Add(p2);
 
            row.Cells.Add(cell);
            whatEverTable.AddRow(row);
            section.Children.Add(whatEverTable);
            document.Children.Add(section);
            radRichTextBox.Document = document;
        }
    }
}
the according xaml (no suprise):
<UserControl x:Class="FootnoteExample.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadRichTextBox
            IsSpellCheckingEnabled="False"
            x:Name="radRichTextBox"
            ShowComments="False"
            Margin="24 24 0 0" />
    </Grid>
</UserControl>

Thanks in advance!
Daniela

7 Answers, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 28 Nov 2012, 02:55 PM
Hello Daniela,

There are several comments I'd like to make regarding the way you are creating your document and you can find the actual modified code at the bottom.

When it comes to tables, inserting one from the UI inserts an empty paragraph before and after the table. This prevents certain layout issues and you should perceive the same approach when building the document in code-behind.

As for programatically creating a document, there are certain properties implemented which can be used when building your RadDocument. Though hierarchically right, you should not be using the Children property of the document elements for adding to the collection. In our online documentation you can find an example of a document built run-time.

Regarding footnotes, they are actually annotations. To be more precise, both the number inserted in your document body and at the end of the page are different annotations. The proper way to initialize such document element is by adding its RangeStart and RangeEnd. I have added such field in the code below.

For future reference, if you hesitate regarding the proper way to create a document element at run time, you can create it in our online demo and export it to XAML. In the generated file you'll be able to see the exact structure of the document.

RadDocument mainDocument = new RadDocument();
mainDocument.LayoutMode = DocumentLayoutMode.Paged;
Section mainDocSection = new Section();
mainDocSection.Blocks.Add(new Paragraph());
 
Table table = new Table();
table.StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName;
TableRow row = new TableRow();
 
TableCell cell = new TableCell();
cell.Padding = new Telerik.Windows.Documents.Layout.Padding(0);
Paragraph cellParagraph = new Paragraph();
cellParagraph.LineSpacing = 1;
Span cellSpan = new Span();
cellSpan.Text = "This is my text";
 
FootnoteRangeEnd footnoteRangeEnd = new FootnoteRangeEnd();
FootnoteRangeStart footnoteRangeStart = (FootnoteRangeStart)footnoteRangeEnd.CreatePairedStart();
 
RadDocument footnoteBody = new RadDocument();
Section footnoteSection = new Section();
Paragraph footnoteParagraph = new Paragraph();
 
Span footnoteSpan = new Span("My footnote text!");
 
NoteReferenceMarkEnd referenceEnd = new NoteReferenceMarkEnd();
NoteReferenceMarkStart referenceStart = (NoteReferenceMarkStart)referenceEnd.CreatePairedStart();
Span s = new Span("footnote")//text is not take into account, but you should not create empty Spans
{
    StyleName = RadDocumentDefaultStyles.FootnoteReferenceStyleName
};
footnoteParagraph.Inlines.Add(referenceStart);
footnoteParagraph.Inlines.Add(s);
footnoteParagraph.Inlines.Add(referenceEnd);
 
footnoteParagraph.Inlines.Add(footnoteSpan);
footnoteSection.Blocks.Add(footnoteParagraph);
footnoteBody.Sections.Add(footnoteSection);
 
footnoteRangeEnd.Note = new Note();
footnoteRangeEnd.Note.Body = footnoteBody;
 
cellParagraph.Inlines.Add(cellSpan);
cellParagraph.Inlines.Add(footnoteRangeStart);
cellParagraph.Inlines.Add(new Span("footnote")//text is not take into account, but you should not create empty Spans
{
    StyleName=RadDocumentDefaultStyles.FootnoteReferenceStyleName
});
cellParagraph.Inlines.Add(footnoteRangeEnd);
 
cell.Blocks.Add(cellParagraph);
row.Cells.Add(cell);
table.AddRow(row);
 
mainDocSection.Blocks.Add(table);
mainDocSection.Blocks.Add(new Paragraph());
 
mainDocument.Sections.Add(mainDocSection);
editor.Document = mainDocument;

I hope this is helpful. Feel free to contact us again if you have other questions.

 
All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Daniela
Top achievements
Rank 1
answered on 02 Oct 2013, 10:55 AM
Hello!
I'm on this issue again :-)
After your post some time is gone and now we want to enhance the footnotes. We implemented everything the way you described above. Now, our customer want to "reuse" existing footnotes. I make an example to clarify:
There is a footnote 1 with the Text "my footnote" in a RadDocument. Now the user wants to add a reference to the same footnote 1. As you can see in the attached image, there are two references to footnote 2 and 5.
Is this possible to implement with the footnote concept of the radrichtextbox?
0
Petya
Telerik team
answered on 07 Oct 2013, 10:27 AM
Hi Daniela,

This is currently not possible using the Footnote functionality of RadRichTextBox. We will consider adding such functionality for one of our future releases.

Let us know if we can further assist you.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Susil
Top achievements
Rank 1
answered on 19 Mar 2015, 07:44 AM
Hello this is Susil.....
Q??
--------
In my project i have used telrik Grid(not Kendo) in that i have a Description column.
For this Description I have used RichTextBox(input). When ever  i am clicking on Edit icon data comes to my edit window but when i am updating data  on Description column comes like  "&kbb&buibbj"  this Encoded format So please give a code description to solve this one.
Hope Question Understood...
0
Tanya
Telerik team
answered on 23 Mar 2015, 11:39 AM
Hi Susil,

As it is not clear from your post, I would like you to confirm that you are using Telerik's RadGridVew for Silverlight with RadRichTextBox for Silverlight inside it. 

If this is the case, RadRichTextBox needs a data provider in order to be bound:
<DataTemplate>
    <StackPanel>
        <telerik:TxtDataProvider Name="dataProvider"
                                    Text="{Binding Path=FirstName, Mode=TwoWay}"
                                    RichTextBox="{Binding ElementName=radRichTextBox}" />
 
        <telerik:RadRichTextBox Name="radRichTextBox" >
        </telerik:RadRichTextBox>
    </StackPanel>
</DataTemplate>

In case this is not helpful for you, please send us more details about the scenario (exact version of the controls you are using, implementation, etc.).

Hope this helps.

Regards,
Tanya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Susil
Top achievements
Rank 1
answered on 24 Mar 2015, 09:45 AM
Actually in my ASP.NET MVC Project i have taken a Telerik grid in XXX.cshtml page  in which one of the column is (say: Comments) .
Now i am using a popup window to insert a Record into the database in that popup i have used a RichTextBox control (Not Rad) for Comments Field.
But problem is that when i am retriving Data from DataBase and showing in Grid data comes in Encoded Format.

Hope this time my Question is Understandable. 
0
Tanya
Telerik team
answered on 25 Mar 2015, 04:37 PM
Hello Susil,

We are doing our best to keep the forums well-structured and easy for searching. As this forum is for Telerik's controls for Silverlight, I would like to ask you if you have future questions for our controls, please, submit them in the correct forum.

Regarding the issue you are experiencing, it seems to be coming from the RichTextBox, but this is a Microsoft control and we could not give you any advice about it. You can try posting on a forum where general programming techniques and questions are discussed like stackoverflow.

Regards,
Tanya
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
RichTextBox
Asked by
Daniela
Top achievements
Rank 1
Answers by
Petya
Telerik team
Daniela
Top achievements
Rank 1
Susil
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or