HTML DataProvider styles are not in line.

1 Answer 9 Views
RichTextBox
Patrick
Top achievements
Rank 1
Iron
Iron
Iron
Patrick asked on 01 May 2024, 06:58 PM | edited on 02 May 2024, 01:33 PM

I have an HTML data provider added in XAML and it is bound to a string.

I have an items control within an items control and this is dynamically generated for each section.

I have followed all documentation online and do not know why my output is not showing style inline. Verified that it works and functions outside of the ItemsControl and just inside a grid. But I need it work below.......

 

Update 5/2/24 -- the HTLM dataProvider is working, but it is almost like all the settings in htmlExportSettings are being completely ignored.

<ItemsControl ItemsSource="{Binding MySections}">
	<ItemsControl.ItemTemplate>
		<ItemContainerTemplate>
			<Grid>
				<ItemsControl ItemsSource="{Binding MySections.MyControls}">
					<ItemsControl.ItemTemplate>
						<ItemContainerTemplate>
							<Grid>
									<telerik:HtmlDataProvider RichTextBox="{Binding ElementName=radRichTextBox}" Html="{Binding MyRichText, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" >
										<telerik:HtmlDataProvider.FormatProvider>
											<telerik:HtmlFormatProvider>
												<telerik:HtmlFormatProvider.ExportSettings>
													<telerik:HtmlExportSettings DocumentExportLevel="Fragment"
																				ImageExportMode="UriSource"
																				ExportStyleMetadata="False"
																				StyleRepositoryExportMode="DontExportStyles"
																				StylesExportMode="Inline"
																				ExportHeadingsAsTags="True"
																				ExportFontStylesAsTags="True"
																				ExportBoldAsStrong="true"
																				ExportItalicAsEm="True"
																				ExportEmptyDocumentAsEmptyString="True"/>
												</telerik:HtmlFormatProvider.ExportSettings>
											</telerik:HtmlFormatProvider>
										</telerik:HtmlDataProvider.FormatProvider>
									</telerik:HtmlDataProvider>

									<telerik:RadRichTextBox x:Name="radRichTextBox" IsSelectionMiniToolBarEnabled="False" IsContextMenuEnabled="True" IsSpellCheckingEnabled="True" LayoutMode="Paged"/>
							</Grid>
						</ItemContainerTemplate>
					</ItemsControl.ItemTemplate>
				</ItemsControl>
				</Grid>
		</ItemContainerTemplate>
	</ItemsControl.ItemTemplate>
</ItemsControl>

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 03 May 2024, 09:53 AM

Hello Patrick,

This is a known behavior caused by a glitch in the WPF XAML parsing system. The exact reason is not clear, because this happens under the hood of the XAML parsing engine, but in general the HtmlDataProvider's ExportSettings property is not assigned to the object defined in XAML (when the HtmlDataProvider is defined in a DataTemplate). Instead it uses its default value.

To work this around, you can wrap the XAML with the HtmlDataProvider and the RadRichTextbox in a new UserControl and use this in the template.

<UserControl x:Class="WpfApp92.MyRichTextBoxUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp92" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
   <Grid>
		<telerik:HtmlDataProvider RichTextBox="{Binding ElementName=radRichTextBox}" Html="{Binding MyRichText, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}" >
			<telerik:HtmlDataProvider.FormatProvider>
				<telerik:HtmlFormatProvider>
					<telerik:HtmlFormatProvider.ExportSettings>
						<telerik:HtmlExportSettings DocumentExportLevel="Fragment"
													ImageExportMode="UriSource"
													ExportStyleMetadata="False"
													StyleRepositoryExportMode="DontExportStyles"
													StylesExportMode="Inline"
													ExportHeadingsAsTags="True"
													ExportFontStylesAsTags="True"
													ExportBoldAsStrong="true"
													ExportItalicAsEm="True"
													ExportEmptyDocumentAsEmptyString="True"/>
					</telerik:HtmlFormatProvider.ExportSettings>
				</telerik:HtmlFormatProvider>
			</telerik:HtmlDataProvider.FormatProvider>
		</telerik:HtmlDataProvider>
		<telerik:RadRichTextBox x:Name="radRichTextBox" IsSelectionMiniToolBarEnabled="False" IsContextMenuEnabled="True" IsSpellCheckingEnabled="True" LayoutMode="Paged"/>
	</Grid>
</UserControl>

 

<ItemsControl.ItemTemplate>
	<ItemContainerTemplate>
		<local:MyRichTextBoxUserControl />
	</ItemContainerTemplate>
</ItemsControl.ItemTemplate>

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Patrick
Top achievements
Rank 1
Iron
Iron
Iron
commented on 03 May 2024, 01:30 PM

Thank you, this solved the issue.

 

Tags
RichTextBox
Asked by
Patrick
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or