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

HTML Format

6 Answers 491 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Pablo Tola
Top achievements
Rank 2
Pablo Tola asked on 07 Feb 2011, 10:33 PM
I'm binding a richtextbox to a viewmodel property, not exporting.
I need to format the output HTML, I don't want the document declaration and I don't want style sheets, I want the styles inline.
How do I get access to the formater to setup those options?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Ivailo Karamanolev
Telerik team
answered on 08 Feb 2011, 03:11 PM
Hello Pablo Tola,

Using the following declarations
xmlns:telerikHtml="clr-namespace:Telerik.Windows.Documents.FormatProviders.Html;assembly=Telerik.Windows.Documents.FormatProviders.Html"
xmlns:telerikHtmlMain="clr-namespace:Telerik.Windows.Documents.FormatProviders.Html;assembly=Telerik.Windows.Documents"
you can declare the data provider like this and it will use DocumentExportLevel=Fragment. You can also customize the HtmlExportSettings any other way you want.
<telerikHtml:HtmlDataProvider x:Key="dataProvider" RichTextBox="{Binding ElementName=richTextBox}">
    <telerikHtml:HtmlDataProvider.FormatProvider>
        <telerikHtml:HtmlFormatProvider>
            <telerikHtml:HtmlFormatProvider.ExportSettings>
                <telerikHtmlMain:HtmlExportSettings DocumentExportLevel="Fragment" />
            </telerikHtml:HtmlFormatProvider.ExportSettings>
        </telerikHtml:HtmlFormatProvider>
    </telerikHtml:HtmlDataProvider.FormatProvider>
</telerikHtml:HtmlDataProvider>


Kind regards,
Ivailo
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Animesh Dey
Top achievements
Rank 2
answered on 19 Oct 2011, 02:23 PM
Hi Ivailo Karamanolev,
I faced a problem when radtextbox is inside DataTemplate.  DocumentExportLevel="Fragment" is not working on that situation.
View:
<StackPanel>
    <telerikHTML:HtmlDataProvider  Name="dp1" Html="{Binding HtmlText, Mode=TwoWay}" RichTextBox="{Binding ElementName=txtChat}">
        <telerikHTML:HtmlDataProvider.FormatProvider>
            <telerikHTML:HtmlFormatProvider>
                <telerikHTML:HtmlFormatProvider.ExportSettings>
                    <telerikHtmlMain:HtmlExportSettings DocumentExportLevel="Fragment"/>
                </telerikHTML:HtmlFormatProvider.ExportSettings>
            </telerikHTML:HtmlFormatProvider>
        </telerikHTML:HtmlDataProvider.FormatProvider>
    </telerikHTML:HtmlDataProvider>
    <my:RadRichTextBox x:Name="txtChat"></my:RadRichTextBox>
</StackPanel>
public class ViewModel : INotifyPropertyChanged
   {
       #region Property(s)
       private readonly DelegateCommand<object> _addCommand;
       public ICommand AddCommand
       {
           get { return _addCommand; }
       }
       string htmlText;
       public string HtmlText
       {
           get { return htmlText; }
           set
           {
               if (htmlText != value)
               {
                   htmlText = value;
                   OnPropertyChanged("HtmlText");
               }
           }
       }
 
 
       private ObservableCollection<ChatItem> _ChatItems;
       public ObservableCollection<ChatItem> ChatItems
       {
           get { return _ChatItems; }
           set { _ChatItems = value; OnPropertyChanged("ChatItems"); }
       }
       #endregion
 
 
       #region Constructor(s)
       public ViewModel()
       {
           _addCommand = new DelegateCommand<object>(OnAddClick);
 
           this.ChatItems = new ObservableCollection<ChatItem>();
           ChatItems.Add(new ChatItem() { Message = "Hello" });
       }
       #endregion
 
       private void OnAddClick(object agrs)
       {
           var html = this.ChatItems[0].Message;
       }
 
       #region INotifyPropertyChanged
       public event PropertyChangedEventHandler PropertyChanged;
 
       private void OnPropertyChanged(string propertyName)
       {
           if (this.PropertyChanged != null)
           {
               this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
           }
       }
       #endregion
   }
   public class ChatItem : INotifyPropertyChanged
   {
       private string _message;
       public string Message
       {
           get { return _message; }
           set { _message = value; OnPropertyChanged("Message"); }
       }
 
       #region INotifyPropertyChanged
       public event PropertyChangedEventHandler PropertyChanged;
 
       private void OnPropertyChanged(string propertyName)
       {
           if (this.PropertyChanged != null)
           {
               this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
           }
       }
       #endregion
   }

Would you please show me a way....
Regards
Animesh
0
Boby
Telerik team
answered on 25 Oct 2011, 08:32 AM
Hello Animesh Dey,
Document export level in data template works as expected at our side. You can read more about the various ways to customize the export in our help section.
If  you continue to experience problems, please send us (through a support ticket) sample project that demonstrates the problem, so we can investigate it further.

Greetings,
Boby
the Telerik team

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

0
Birgit
Top achievements
Rank 1
answered on 26 May 2016, 01:20 PM

Hello

I've the same problem.

When i have a radrichtextbox inside a DataTemplate (RadDataForm) the  HtmlImportSettings from HtmlDataProvider is not working.

<Grid>
    <Grid.Resources>
        <DataTemplate x:Key="MyTemplate">
            <StackPanel>
                <telerik:DataFormDataField  Label="First Name" DataMemberBinding="{Binding FirstName, Mode=TwoWay}" />
                <telerik:DataFormDataField  Label="Last Name" DataMemberBinding="{Binding LastName, Mode=TwoWay}" />
 
                <telerik:HtmlDataProvider x:Name="htmlDataProvider" RichTextBox="{Binding ElementName=richTextBox}" Html="{Binding HtmlBody, Mode=TwoWay}">
                    <telerik:HtmlDataProvider.FormatProvider>
                        <telerik:HtmlFormatProvider>
                            <telerik:HtmlFormatProvider.ImportSettings>
                                <telerik:HtmlImportSettings  UseDefaultStylesheetForFontProperties="True" />
                            </telerik:HtmlFormatProvider.ImportSettings>
                            <telerik:HtmlFormatProvider.ExportSettings>
                                <telerik:HtmlExportSettings DocumentExportLevel="Fragment"
                                                        ImageExportMode="UriSource"
                                                        ExportFontStylesAsTags="True"
                                                        ExportStyleMetadata="False"
                                                        StyleRepositoryExportMode="DontExportStyles"
                                                        StylesExportMode="Inline"/>
                            </telerik:HtmlFormatProvider.ExportSettings>
                        </telerik:HtmlFormatProvider>
                    </telerik:HtmlDataProvider.FormatProvider>
                </telerik:HtmlDataProvider>
                <telerik:RadRichTextBox x:Name="richTextBox"/>
 
            </StackPanel>
        </DataTemplate>
    </Grid.Resources>
    <telerik:RadDataForm x:Name="DataForm1"
                         AutoGenerateFields="False"
                         ReadOnlyTemplate="{StaticResource MyTemplate}"
                         EditTemplate="{StaticResource MyTemplate}"
                         NewItemTemplate="{StaticResource MyTemplate}">
    </telerik:RadDataForm>
</Grid>

Same code without RadDataForm works perfect.

Did you have a workaround for this problem?

Kind regards

Bigi

0
Petya
Telerik team
answered on 31 May 2016, 08:42 AM
Hello ,

Upon further investigation, it looks like this behavior comes from the WPF framework although I have not been able to isolate the exact cause. This explanation on and the Dependency Property Value Precedence topic on MSDN suggest that dependency properties in data templates might fall back to their default value unexpectedly. The workaround provided in the conversation to place the control along with the provider in a UserControl seem to resolve this, so I'd suggest trying it out.

I hope this helps.

Regards,
Petya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Birgit
Top achievements
Rank 1
answered on 11 Jul 2017, 12:42 PM

My workaround is:  do not use RadDataForm.

I have built my own control for the navigation and action buttons.

Tags
RichTextBox
Asked by
Pablo Tola
Top achievements
Rank 2
Answers by
Ivailo Karamanolev
Telerik team
Animesh Dey
Top achievements
Rank 2
Boby
Telerik team
Birgit
Top achievements
Rank 1
Petya
Telerik team
Share this question
or