HTML Format

6 posts, 0 answers
  1. Pablo Tola
    Pablo Tola avatar
    43 posts
    Member since:
    Nov 2007

    Posted 07 Feb 2011 Link to this post

    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.
  2. Ivailo Karamanolev
    Admin
    Ivailo Karamanolev avatar
    276 posts

    Posted 08 Feb 2011 Link to this post

    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>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Animesh Dey
    Animesh Dey avatar
    24 posts
    Member since:
    Jul 2012

    Posted 19 Oct 2011 Link to this post

    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
  5. Boby
    Admin
    Boby avatar
    595 posts

    Posted 25 Oct 2011 Link to this post

    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 >>

  6. Birgit
    Birgit avatar
    1 posts
    Member since:
    Apr 2016

    Posted 26 May Link to this post

    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

  7. Petya
    Admin
    Petya avatar
    975 posts

    Posted 31 May Link to this post

    Hello Bigi,

    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 stackoverflow 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.
Back to Top
UI for WPF is Visual Studio 2017 Ready