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

Import HTML from DB, Underline decoration issue

16 Answers 418 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Téo
Top achievements
Rank 1
Téo asked on 26 Jul 2011, 07:17 PM

Hi Telerik Team,

 

I use your RichTextBox control.

 

I use the Import/Export HTML mode with HTMLProvider.

 

If i underline a word and I export in HTML the tag "text-decoration: underline;" is visible.

 

But when I import the same HTML, the word is not underlined.

 

I made a labs basic to prove this. If i can send this to you for helping It is with pleasure.

Téo

16 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 29 Jul 2011, 02:58 PM
Hello Téo,

Thank you for reporting this bug.
We will make sure to fix it in the service pack or internal build before that.

Best wishes,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Kris Drouet
Top achievements
Rank 1
answered on 04 Feb 2012, 12:24 AM
I am using the HtmlDataProvider and the underline text is not persisting when I read MyBody property.  I have tried loading an xhtml compliant html, html with inline styles, <u> tags and loading a plain document and using the binding commands for underline with no luck.  I am using the latest version,RadControls for Silverlight Q3 2011 SP1.  Am I missing something?
  <UserControl.Resources>
        <telerikHtml:HtmlDataProvider x:Name="HtmlProvider" RichTextBox="{Binding ElementName=editor}" Html="{Binding MyBody, Mode=TwoWay}" FormatProvider="{Binding HtmlFormatProvider}"/>
    </UserControl.Resources>
<telerik:RadRichTextBox AllowScaling="False"  Height="282" HorizontalScrollBarVisibility="Hidden" IsContextMenuEnabled="False" IsSelectionMiniToolBarEnabled="False" IsSpellCheckingEnabled="False" Name="editor" VerticalScrollBarVisibility="Hidden" Width="400" />

Thanks,

Kris
0
Iva Toteva
Telerik team
answered on 07 Feb 2012, 07:21 PM
Hi Kris,

Thank you for reporting this bug. It is related to the newly introduced style system. We have updated your Telerik points in appreciation of your involvement.
As a workaround, you can use HtmlExportSettings and specify StyleRepositoryExportMode to DontExportStyles.

On a side note, when you use data-binding, you have to declare the data provider in the visual tree, as noted in this article. This ensures that the DataContext of the data provider will be properly updated if it is changed for some reason. Furthermore, you must not declare/bind the FormatProvider of the data provider. It is exposed in order to enable finer customization of the import/export through the settings.

In a nut-shell, your code should read:

<Grid>
    <telerikHtml:HtmlDataProvider x:Name="HtmlProvider" RichTextBox="{Binding ElementName=editor}" Html="{Binding MyBody, Mode=TwoWay}">
        <telerikHtml:HtmlDataProvider.FormatProvider>
            <telerikHtml:HtmlFormatProvider>
                <telerikHtml:HtmlFormatProvider.ExportSettings>
                    <telerikHtmlSettings:HtmlExportSettings StyleRepositoryExportMode="DontExportStyles" />
                </telerikHtml:HtmlFormatProvider.ExportSettings>
            </telerikHtml:HtmlFormatProvider>
        </telerikHtml:HtmlDataProvider.FormatProvider>
    </telerikHtml:HtmlDataProvider>
    <telerik:RadRichTextBox AllowScaling="False"  Height="282" HorizontalScrollBarVisibility="Hidden" IsContextMenuEnabled="False" IsSelectionMiniToolBarEnabled="False" IsSpellCheckingEnabled="False" Name="editor" VerticalScrollBarVisibility="Hidden" Width="400" />
</Grid>

where telerikHtmlSettings namespace is:
xmlns:telerikHtmlSettings="clr-namespace:Telerik.Windows.Documents.FormatProviders.Html;assembly=Telerik.Windows.Documents"
All the best,
Iva Toteva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Kris Drouet
Top achievements
Rank 1
answered on 07 Feb 2012, 07:39 PM
I am created a workaround to solve the bug in the HtmlFormatProvider.
Use XmlDataProvider instead and convert the html to Xaml by doing the following:
<telerikXaml:XamlDataProvider x:Name="XamlProvider" RichTextBox="{Binding ElementName=editor}" Xaml="{Binding MyXaml, Mode=TwoWay}" />

string html = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
    <head>
        <title>Untitled</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
        <style type='text/css'>
            .p_CC664AAA { margin: 0px 0px 12px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px; }
            .s_1681A555 { font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000; }
        </style>
    </head>
    <body>
        <p class='p_CC664AAA'>
            <span class='s_1681A555'>This is <strong>bold</strong> text, this is <em>italic</em> text, and this is <span><u>underlined</u></span> text.</span>
        </p>
    </body>
</html>";
            //Workaround for a bug in the RadRichTextBox control
            XamlDataProvider provider = new XamlDataProvider();
            provider.FormatProvider = new HtmlFormatProvider();
            provider.Xaml = html;
            provider.RichTextBox = new RadRichTextBox();
            MyXaml = new XamlFormatProvider().Export(provider.RichTextBox.Document);

Once the xaml is loaded you can extract the html from the radrichtext editor:
RadDocument doc = new XamlFormatProvider().Import(MyXaml);
string html = new HtmlFormatProvider().Export(doc);
0
Iva Toteva
Telerik team
answered on 07 Feb 2012, 08:31 PM
You seem to have misunderstood the use of the format providers, the data providers and the nature of the issue. Let me elaborate a bit on the whole usage of these items.

1. FormatProviders are meant to be used when you import/export a document to one of the supported formats. For example, they are used in the OpenDocumentCommand and SaveCommand which open/save documents as files on the client machine through the OpenFileDialog and the SaveFileDialog.

2. DataProviders are built on top of FormatProviders in order to enable data-binding. They track when the document content is changed and update the property that they are bound to and vice versa - update the document when the property notifies that it has been changed. The data providers create an instance of the respective format provider internally (HTML, XAML, etc.) and use it to import/export the document.

Now, the code in your snippet that creates a XamlDataProvider, HtmlFormatProvider and RadRichTextBox in code-behind and exports the document to XAML is equivalent to:
RadDocument document = new HtmlFormatProvider().Import(html);
MyXaml = new XamlFormatProvider().Import(document);

Since there is no problem with the HTML import, as well as XAML import and export, "document" will be correct and will have all the formatting specified in the initial string. Due to the fact that you are using XamlDataProvider in XAML, the content of the RadRichTextBox will also be correct.

Proceeding with your code, importing MyXaml will just create the same document as the one kept in "document" ("doc" will be the same as "document", correctly preserving the formatting).

Then, when you export the document with the default HTML export, the underlines will be lost again. The value of html at the end will be as in the attached file. As you can see, the style for the underlined span (s_C676007D) does not include an underline.


So, basically, you have two options:
1. Use XamlDataProvider in XAML, just convert the initial input to XAML as in my first snippet.
2. Use HtmlDataProvider in XAML, setting StyleRepositoryExportMode to DontExportStyles, as in the snippet in my previous post.

I hope this helps.

All the best,
Iva Toteva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Chaitanya
Top achievements
Rank 1
answered on 25 Apr 2012, 01:16 PM
I am having same problem of underline...but when i change HTMLExportSettings StyleRepositoryExportMode option to "DontExportStyles" then my problem is solved for normal underline.
Now when i use dashed,dotted or wave types underline then it showing on the selected text but when i save it and try to reaccess it from database then it will display as a normal underline not one which is selected i.e wave, dashed or dotted..

I was not able to set ExportFontStylesAsTags option of HtmlExportSettings to true.

please suggest some solution for it.
0
Iva Toteva
Telerik team
answered on 27 Apr 2012, 11:13 AM
Hello Chaitanya,

HtmlFormatProvider exports all underlines as Single underlines, i.e. using the text-decoration property and setting it to underline (text-decoration: underline;). We will consider implementing different export of the underlines, but it is not clear if and when it will be implemented.

When it comes to the ExportFontStylesAsTags property, it has been introduced in one of the latest versions, so the reason why you can't set it is probably that you are using an older version of the controls. However, when you set it to "True", the underlines will be exported as <u>[underlined text]</u> and again the style of the underlines will not be saved.

All the best,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Chaitanya
Top achievements
Rank 1
answered on 29 Apr 2012, 02:42 PM
Firstly thanks for your quick response. I want to know, what can i need to do to save style of underline. Please suggest me solution to save different styles of underline.

Thank you.
 
0
Boby
Telerik team
answered on 02 May 2012, 09:47 AM
Hello Chaitanya,
As Iva posted, in the current version the default HtmlFormatProvider doesn't preserve the underline style in the output HTML. We will, however, consider adding such feature in future releases.

Regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Chaitanya
Top achievements
Rank 1
answered on 02 May 2012, 05:34 PM
So, can we save underline style using XML Format provider instead of HTML format provider ? or it also have same problem.

Thank you.
0
Iva Toteva
Telerik team
answered on 04 May 2012, 03:19 PM
Hi Chaitanya,

We are not aware of any issues with the XAML export and import of underlines. Overall it is recommended to use XAML to persist documents viewed in RadRichTextBox, because XAML is closest to our internal document format and ensures best serialization of all rich text features. In comparison, HTML format provider does not persist headers and footers and some other properties that have no analog in HTML.

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Chaitanya
Top achievements
Rank 1
answered on 04 May 2012, 03:52 PM
Thank you.
0
afsarsal
Top achievements
Rank 1
answered on 30 Dec 2014, 12:09 PM
Hello Boby,

Is there any progress for this case.
I'm dealing with exactly the same scenario.

Thanks in advance,
Salim

[quote]Boby said:Hello Chaitanya,
As Iva posted, in the current version the default HtmlFormatProvider doesn't preserve the underline style in the output HTML. We will, however, consider adding such feature in future releases.

Regards,
Boby
the Telerik team
 

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

 
[/quote]
0
Anna
Telerik team
answered on 30 Dec 2014, 03:50 PM
Hi Salim,

At the moment we don't plan on implementing import and export of the underline style for the HTMLFormatProvider. One of the main reasons for this is that the text-decoration-style property is not supported by most browsers.

Regards,
Anna
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
afsarsal
Top achievements
Rank 1
answered on 20 Apr 2015, 07:31 AM

Hi Anna,

 

How can I remove/hide Underline decorations on the font properties dialog ?

 

Thanks

0
Anna
Telerik team
answered on 22 Apr 2015, 01:03 PM
Hi,

I am attaching a solution which demonstrates an implementation of a custom font properties dialog with the Underline section removed.

I hope this helps.

Regards,
Anna
Telerik
 

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

 
Tags
RichTextBox
Asked by
Téo
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Kris Drouet
Top achievements
Rank 1
Chaitanya
Top achievements
Rank 1
Boby
Telerik team
afsarsal
Top achievements
Rank 1
Anna
Telerik team
Share this question
or